xref: /freebsd/share/man/man9/make_dev.9 (revision 1a720cbec513210fa2e85c3882741ef2f6dc5f35)
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.\"
25a54cfe70SBryan Drewery.Dd March 2, 2016
2694b1839dSChris Costello.Dt MAKE_DEV 9
27aa12cea2SUlrich Spörlein.Os
2894b1839dSChris Costello.Sh NAME
2994b1839dSChris Costello.Nm make_dev ,
30fe754649SKonstantin Belousov.Nm make_dev_cred ,
31fe754649SKonstantin Belousov.Nm make_dev_credf ,
32f36575b5SJaakko Heinonen.Nm make_dev_p ,
3348ce5d4cSKonstantin Belousov.Nm make_dev_s ,
34f14b89faSDima Dorfman.Nm make_dev_alias ,
358137364fSAndrey V. Elsukov.Nm make_dev_alias_p ,
36f14b89faSDima Dorfman.Nm destroy_dev ,
37fe754649SKonstantin Belousov.Nm destroy_dev_sched ,
38fe754649SKonstantin Belousov.Nm destroy_dev_sched_cb ,
39fe754649SKonstantin Belousov.Nm destroy_dev_drain ,
4044c63b64SDima Dorfman.Nm dev_depends
41e3718e31SRuslan Ermilov.Nd manage
42c97dc39fSChristian Brueffer.Vt cdev Ns 's
43e3718e31SRuslan Ermilovand DEVFS registration for devices
4494b1839dSChris Costello.Sh SYNOPSIS
45212c98aaSBruce Evans.In sys/param.h
4632eef9aeSRuslan Ermilov.In sys/conf.h
4748ce5d4cSKonstantin Belousov.Ft void
4848ce5d4cSKonstantin Belousov.Fn make_dev_args_init "struct make_dev_args *args"
49f36575b5SJaakko Heinonen.Ft int
5048ce5d4cSKonstantin Belousov.Fn make_dev_s "struct make_dev_args *args" "struct cdev **cdev" "const char *fmt" ...
518137364fSAndrey V. Elsukov.Ft int
528137364fSAndrey V. Elsukov.Fn make_dev_alias_p "int flags" "struct cdev **cdev" "struct cdev *pdev" "const char *fmt" ...
5394b1839dSChris Costello.Ft void
54097fcfebSWarner Losh.Fn destroy_dev "struct cdev *dev"
55f14b89faSDima Dorfman.Ft void
56fe754649SKonstantin Belousov.Fn destroy_dev_sched "struct cdev *dev"
57fe754649SKonstantin Belousov.Ft void
58fe754649SKonstantin Belousov.Fn destroy_dev_sched_cb "struct cdev *dev" "void (*cb)(void *)" "void *arg"
59fe754649SKonstantin Belousov.Ft void
60fe754649SKonstantin Belousov.Fn destroy_dev_drain "struct cdevsw *csw"
61fe754649SKonstantin Belousov.Ft void
62097fcfebSWarner Losh.Fn dev_depends "struct cdev *pdev" "struct cdev *cdev"
6348ce5d4cSKonstantin Belousov.Pp
6448ce5d4cSKonstantin BelousovLEGACY INTERFACES
6548ce5d4cSKonstantin Belousov.Ft struct cdev *
6648ce5d4cSKonstantin Belousov.Fn make_dev "struct cdevsw *cdevsw" "int unit" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ...
6748ce5d4cSKonstantin Belousov.Ft struct cdev *
6848ce5d4cSKonstantin Belousov.Fn make_dev_cred "struct cdevsw *cdevsw" "int unit" "struct ucred *cr" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ...
6948ce5d4cSKonstantin Belousov.Ft struct cdev *
7048ce5d4cSKonstantin 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" ...
7148ce5d4cSKonstantin Belousov.Ft int
7248ce5d4cSKonstantin 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" ...
7348ce5d4cSKonstantin Belousov.Ft struct cdev *
7448ce5d4cSKonstantin Belousov.Fn make_dev_alias "struct cdev *pdev" "const char *fmt" ...
7594b1839dSChris Costello.Sh DESCRIPTION
7694b1839dSChris CostelloThe
7748ce5d4cSKonstantin Belousov.Fn make_dev_s
7894b1839dSChris Costellofunction creates a
79c97dc39fSChristian Brueffer.Fa cdev
8048ce5d4cSKonstantin Belousovstructure for a new device, which is returned into the
8148ce5d4cSKonstantin Belousov.Fa cdev
8248ce5d4cSKonstantin Belousovargument.
83fe754649SKonstantin BelousovIt also notifies
84*1a720cbeSAlexander Ziaee.Xr devfs 4
85fe754649SKonstantin Belousovof the presence of the new device, that causes corresponding nodes
86fe754649SKonstantin Belousovto be created.
87fe754649SKonstantin BelousovBesides this, a
88fe754649SKonstantin Belousov.Xr devctl 4
89fe754649SKonstantin Belousovnotification is sent.
9048ce5d4cSKonstantin BelousovThe function takes the structure
9148ce5d4cSKonstantin Belousov.Va struct make_dev_args args ,
9248ce5d4cSKonstantin Belousovwhich specifies the parameters for the device creation:
9348ce5d4cSKonstantin Belousov.Pp
9448ce5d4cSKonstantin Belousov.Bd -literal -offset indent -compact
9548ce5d4cSKonstantin Belousovstruct make_dev_args {
9648ce5d4cSKonstantin Belousov	size_t		 mda_size;
9748ce5d4cSKonstantin Belousov	int		 mda_flags;
9848ce5d4cSKonstantin Belousov	struct cdevsw	*mda_devsw;
9948ce5d4cSKonstantin Belousov	struct ucred	*mda_cr;
10048ce5d4cSKonstantin Belousov	uid_t		 mda_uid;
10148ce5d4cSKonstantin Belousov	gid_t		 mda_gid;
10248ce5d4cSKonstantin Belousov	int		 mda_mode;
10348ce5d4cSKonstantin Belousov	int		 mda_unit;
10448ce5d4cSKonstantin Belousov	void		*mda_si_drv1;
10548ce5d4cSKonstantin Belousov	void		*mda_si_drv2;
10648ce5d4cSKonstantin Belousov};
10748ce5d4cSKonstantin Belousov.Ed
10848ce5d4cSKonstantin BelousovBefore use and filling with the desired values, the structure must be
10948ce5d4cSKonstantin Belousovinitialized by the
11048ce5d4cSKonstantin Belousov.Fn make_dev_args_init
11148ce5d4cSKonstantin Belousovfunction, which ensures that future kernel interface expansion does
11248ce5d4cSKonstantin Belousovnot affect driver source code or binary interface.
11348ce5d4cSKonstantin Belousov.Pp
11448ce5d4cSKonstantin BelousovThe created device will be owned by
11548ce5d4cSKonstantin Belousov.Va args.mda_uid ,
11694b1839dSChris Costellowith the group ownership as
11748ce5d4cSKonstantin Belousov.Va args.mda_gid .
1181dfbd9c2SWarner LoshThe name is the expansion of
1191dfbd9c2SWarner Losh.Va fmt
1201dfbd9c2SWarner Loshand following arguments as
1211dfbd9c2SWarner Losh.Xr printf 9
1221dfbd9c2SWarner Loshwould print it.
1231dfbd9c2SWarner LoshThe name determines its path under
1241dfbd9c2SWarner Losh.Pa /dev
1251dfbd9c2SWarner Loshor other
126*1a720cbeSAlexander Ziaee.Xr devfs 4
1271dfbd9c2SWarner Loshmount point and may contain slash
1281dfbd9c2SWarner Losh.Ql /
1291dfbd9c2SWarner Loshcharacters to denote subdirectories.
13094b1839dSChris CostelloThe permissions of the file specified in
13148ce5d4cSKonstantin Belousov.Va args.mda_mode
13294b1839dSChris Costelloare defined in
133fe08efe6SRuslan Ermilov.In sys/stat.h :
13494b1839dSChris Costello.Pp
13594b1839dSChris Costello.Bd -literal -offset indent -compact
13694b1839dSChris Costello#define S_IRWXU 0000700    /* RWX mask for owner */
13794b1839dSChris Costello#define S_IRUSR 0000400    /* R for owner */
13894b1839dSChris Costello#define S_IWUSR 0000200    /* W for owner */
13994b1839dSChris Costello#define S_IXUSR 0000100    /* X for owner */
14094b1839dSChris Costello
14194b1839dSChris Costello#define S_IRWXG 0000070    /* RWX mask for group */
14294b1839dSChris Costello#define S_IRGRP 0000040    /* R for group */
14394b1839dSChris Costello#define S_IWGRP 0000020    /* W for group */
14494b1839dSChris Costello#define S_IXGRP 0000010    /* X for group */
14594b1839dSChris Costello
14694b1839dSChris Costello#define S_IRWXO 0000007    /* RWX mask for other */
14794b1839dSChris Costello#define S_IROTH 0000004    /* R for other */
14894b1839dSChris Costello#define S_IWOTH 0000002    /* W for other */
14994b1839dSChris Costello#define S_IXOTH 0000001    /* X for other */
15094b1839dSChris Costello
15194b1839dSChris Costello#define S_ISUID 0004000    /* set user id on execution */
15294b1839dSChris Costello#define S_ISGID 0002000    /* set group id on execution */
15394b1839dSChris Costello#define S_ISVTX 0001000    /* sticky bit */
15494b1839dSChris Costello#ifndef _POSIX_SOURCE
15594b1839dSChris Costello#define S_ISTXT 0001000
15694b1839dSChris Costello#endif
15794b1839dSChris Costello.Ed
15894b1839dSChris Costello.Pp
15994b1839dSChris CostelloThe
16048ce5d4cSKonstantin Belousov.Va args.mda_cr
161fe754649SKonstantin Belousovargument specifies credentials that will be stored in the
162fe754649SKonstantin Belousov.Fa si_cred
163fe754649SKonstantin Belousovmember of the initialized
164fe754649SKonstantin Belousov.Fa struct cdev .
16548ce5d4cSKonstantin Belousov.Pp
166fe754649SKonstantin BelousovThe
16748ce5d4cSKonstantin Belousov.Va args.mda_flags
168fe754649SKonstantin Belousovargument alters the operation of
16948ce5d4cSKonstantin Belousov.Fn make_dev_s.
170fe754649SKonstantin BelousovThe following values are currently accepted:
171fe754649SKonstantin Belousov.Pp
17248ce5d4cSKonstantin Belousov.Bl -tag -width "It Dv MAKEDEV_CHECKNAME" -compact -offset indent
17348ce5d4cSKonstantin Belousov.It Dv MAKEDEV_REF
17468f7a013SJaakko Heinonenreference the created device
17548ce5d4cSKonstantin Belousov.It Dv MAKEDEV_NOWAIT
176f36575b5SJaakko Heinonendo not sleep, the call may fail
17748ce5d4cSKonstantin Belousov.It Dv MAKEDEV_WAITOK
17868f7a013SJaakko Heinonenallow the function to sleep to satisfy malloc
17948ce5d4cSKonstantin Belousov.It Dv MAKEDEV_ETERNAL
18068f7a013SJaakko Heinonencreated device will be never destroyed
18148ce5d4cSKonstantin Belousov.It Dv MAKEDEV_CHECKNAME
182f36575b5SJaakko Heinonenreturn an error if the device name is invalid or already exists
18368f7a013SJaakko Heinonen.El
184fe754649SKonstantin Belousov.Pp
1858137364fSAndrey V. ElsukovOnly
1868137364fSAndrey V. Elsukov.Dv MAKEDEV_NOWAIT ,
1878137364fSAndrey V. Elsukov.Dv MAKEDEV_WAITOK
1888137364fSAndrey V. Elsukovand
1898137364fSAndrey V. Elsukov.Dv MAKEDEV_CHECKNAME
1908137364fSAndrey V. Elsukovvalues are accepted for the
1918137364fSAndrey V. Elsukov.Fn make_dev_alias_p
1928137364fSAndrey V. Elsukovfunction.
1938137364fSAndrey V. Elsukov.Pp
194fe754649SKonstantin BelousovThe
1952b848cb1SKonstantin Belousov.Dv MAKEDEV_WAITOK
1962b848cb1SKonstantin Belousovflag is assumed if none of
1972b848cb1SKonstantin Belousov.Dv MAKEDEV_WAITOK ,
1982b848cb1SKonstantin Belousov.Dv MAKEDEV_NOWAIT
1992b848cb1SKonstantin Belousovis specified.
2002b848cb1SKonstantin Belousov.Pp
2012b848cb1SKonstantin BelousovThe
202fe754649SKonstantin Belousov.Xr dev_clone 9
203fe754649SKonstantin Belousovevent handler shall specify
204fe754649SKonstantin Belousov.Dv MAKEDEV_REF
205fe754649SKonstantin Belousovflag when creating a device in response to lookup, to avoid race where
206fe754649SKonstantin Belousovthe device created is destroyed immediately after
207fe754649SKonstantin Belousov.Xr devfs_lookup 9
208fe754649SKonstantin Belousovdrops his reference to cdev.
209fe754649SKonstantin Belousov.Pp
210fe754649SKonstantin BelousovThe
2115e9cd1dbSKonstantin Belousov.Dv MAKEDEV_ETERNAL
2125e9cd1dbSKonstantin Belousovflag allows the kernel to not acquire some locks when translating system
2135e9cd1dbSKonstantin Belousovcalls into the cdevsw methods calls.
2145e9cd1dbSKonstantin BelousovIt is responsibility of the driver author to make sure that
2155e9cd1dbSKonstantin Belousov.Fn destroy_dev
2165e9cd1dbSKonstantin Belousovis never called on the returned cdev.
2175e9cd1dbSKonstantin BelousovFor the convenience, use the
2185e9cd1dbSKonstantin Belousov.Dv MAKEDEV_ETERNAL_KLD
2195e9cd1dbSKonstantin Belousovflag for the code that can be compiled into kernel or loaded
2205e9cd1dbSKonstantin Belousov(and unloaded) as loadable module.
2215e9cd1dbSKonstantin Belousov.Pp
22248ce5d4cSKonstantin BelousovA panic will occur if the
22348ce5d4cSKonstantin Belousov.Dv MAKEDEV_CHECKNAME
22448ce5d4cSKonstantin Belousovflag is not specified
22568f7a013SJaakko Heinonenand the device name is invalid or already exists.
22668f7a013SJaakko Heinonen.Pp
2275e9cd1dbSKonstantin BelousovThe
22848ce5d4cSKonstantin Belousov.Fn make_dev_p
22948ce5d4cSKonstantin Belousovuse of the form
23048ce5d4cSKonstantin Belousov.Bd -literal -offset indent
23148ce5d4cSKonstantin Belousovstruct cdev *dev;
23248ce5d4cSKonstantin Belousovint res;
23348ce5d4cSKonstantin Belousovres = make_dev_p(flags, &dev, cdevsw, cred, uid, gid, perms, name);
23448ce5d4cSKonstantin Belousov.Ed
23548ce5d4cSKonstantin Belousovis equivalent to the code
23648ce5d4cSKonstantin Belousov.Bd -literal -offset indent
23748ce5d4cSKonstantin Belousovstruct cdev *dev;
23848ce5d4cSKonstantin Belousovstruct make_dev_args args;
23948ce5d4cSKonstantin Belousovint res;
24048ce5d4cSKonstantin Belousov
24148ce5d4cSKonstantin Belousovmake_dev_args_init(&args);
24248ce5d4cSKonstantin Belousovargs.mda_flags = flags;
24348ce5d4cSKonstantin Belousovargs.mda_devsw = cdevsw;
24448ce5d4cSKonstantin Belousovargs.mda_cred = cred;
24548ce5d4cSKonstantin Belousovargs.mda_uid = uid;
24648ce5d4cSKonstantin Belousovargs.mda_gid = gid;
24748ce5d4cSKonstantin Belousovargs.mda_mode = perms;
24848ce5d4cSKonstantin Belousovres = make_dev_s(&args, &dev, name);
24948ce5d4cSKonstantin Belousov.Ed
25048ce5d4cSKonstantin Belousov.Pp
25148ce5d4cSKonstantin BelousovSimilarly, the
25248ce5d4cSKonstantin Belousov.Fn make_dev_credf
25348ce5d4cSKonstantin Belousovfunction call is equivalent to
25448ce5d4cSKonstantin Belousov.Bd -literal -offset indent
25548ce5d4cSKonstantin Belousov	(void) make_dev_s(&args, &dev, name);
25648ce5d4cSKonstantin Belousov.Ed
25748ce5d4cSKonstantin BelousovIn other words,
25848ce5d4cSKonstantin Belousov.Fn make_dev_credf
25948ce5d4cSKonstantin Belousovdoes not allow the caller to obtain the return value, and in
26048ce5d4cSKonstantin Belousovkernels compiled with the
26148ce5d4cSKonstantin Belousov.Va INVARIANTS
26248ce5d4cSKonstantin Belousovoptions, the function asserts that the device creation succeeded.
26348ce5d4cSKonstantin Belousov.Pp
26448ce5d4cSKonstantin BelousovThe
265fe754649SKonstantin Belousov.Fn make_dev_cred
266fe754649SKonstantin Belousovfunction is equivalent to the call
267fe754649SKonstantin Belousov.Bd -literal -offset indent
268edde8745SEd Schoutenmake_dev_credf(0, cdevsw, unit, cr, uid, gid, perms, fmt, ...);
269e10c1be4SUlrich Spörlein.Ed
270fe754649SKonstantin Belousov.Pp
271fe754649SKonstantin BelousovThe
272fe754649SKonstantin Belousov.Fn make_dev
273fe754649SKonstantin Belousovfunction call is the same as
274fe754649SKonstantin Belousov.Bd -literal -offset indent
275edde8745SEd Schoutenmake_dev_credf(0, cdevsw, unit, NULL, uid, gid, perms, fmt, ...);
276e10c1be4SUlrich Spörlein.Ed
277fe754649SKonstantin Belousov.Pp
278fe754649SKonstantin BelousovThe
27948ce5d4cSKonstantin Belousov.Fn make_dev_alias_p
280792b2369SMatt Jacobfunction takes the returned
281c97dc39fSChristian Brueffer.Ft cdev
282792b2369SMatt Jacobfrom
283792b2369SMatt Jacob.Fn make_dev
284edf0984dSRuslan Ermilovand makes another (aliased) name for this device.
285edf0984dSRuslan ErmilovIt is an error to call
28648ce5d4cSKonstantin Belousov.Fn make_dev_alias_p
287792b2369SMatt Jacobprior to calling
288792b2369SMatt Jacob.Fn make_dev .
289792b2369SMatt Jacob.Pp
29048ce5d4cSKonstantin BelousovThe
29148ce5d4cSKonstantin Belousov.Fn make_dev_alias
2928137364fSAndrey V. Elsukovfunction is similar to
293cc7decfcSMark Johnston.Fn make_dev_alias_p
29448ce5d4cSKonstantin Belousovbut it returns the resulting aliasing
2958137364fSAndrey V. Elsukov.Ft *cdev
29648ce5d4cSKonstantin Belousovand may not return an error.
2978137364fSAndrey V. Elsukov.Pp
298792b2369SMatt JacobThe
2992557913dSJohn-Mark Gurney.Fa cdev
3002557913dSJohn-Mark Gurneyreturned by
30148ce5d4cSKonstantin Belousov.Fn make_dev_s
3022557913dSJohn-Mark Gurneyand
30348ce5d4cSKonstantin Belousov.Fn make_dev_alias_p
3042557913dSJohn-Mark Gurneyhas two fields,
3052557913dSJohn-Mark Gurney.Fa si_drv1
3062557913dSJohn-Mark Gurneyand
3072557913dSJohn-Mark Gurney.Fa si_drv2 ,
30877213b87SChristian Bruefferthat are available to store state.
30977213b87SChristian BruefferBoth fields are of type
31048ce5d4cSKonstantin Belousov.Ft void * ,
31148ce5d4cSKonstantin Belousovand can be initialized simultaneously with the
31248ce5d4cSKonstantin Belousov.Va cdev
31348ce5d4cSKonstantin Belousovallocation by filling
31448ce5d4cSKonstantin Belousov.Va args.mda_si_drv1
31548ce5d4cSKonstantin Belousovand
31648ce5d4cSKonstantin Belousov.Va args.mda_si_drv2
31748ce5d4cSKonstantin Belousovmembers of the
31848ce5d4cSKonstantin Belousov.Fn make_dev_s
31948ce5d4cSKonstantin Belousovargument structure, or filled after the
32048ce5d4cSKonstantin Belousov.Va cdev
32148ce5d4cSKonstantin Belousovis allocated, if using legacy interfaces.
32248ce5d4cSKonstantin BelousovIn the latter case, the driver should handle the race of
32348ce5d4cSKonstantin Belousovaccessing uninitialized
32448ce5d4cSKonstantin Belousov.Va si_drv1
32548ce5d4cSKonstantin Belousovand
32648ce5d4cSKonstantin Belousov.Va si_drv2
32748ce5d4cSKonstantin Belousovitself.
3282557913dSJohn-Mark GurneyThese are designed to replace the
329edde8745SEd Schouten.Fa unit
3302557913dSJohn-Mark Gurneyargument to
33166c6ebfeSEd Schouten.Fn make_dev ,
33266c6ebfeSEd Schoutenwhich can be obtained with
33366c6ebfeSEd Schouten.Fn dev2unit .
3342557913dSJohn-Mark Gurney.Pp
3352557913dSJohn-Mark GurneyThe
336bd00dbfaSBruce Evans.Fn destroy_dev
33794b1839dSChris Costellofunction takes the returned
338c97dc39fSChristian Brueffer.Fa cdev
33994b1839dSChris Costellofrom
34094b1839dSChris Costello.Fn make_dev
341edf0984dSRuslan Ermilovand destroys the registration for that device.
342fe754649SKonstantin BelousovThe notification is sent to
343fe754649SKonstantin Belousov.Xr devctl 4
344fe754649SKonstantin Belousovabout the destruction event.
345edf0984dSRuslan ErmilovDo not call
346792b2369SMatt Jacob.Fn destroy_dev
347792b2369SMatt Jacobon devices that were created with
348792b2369SMatt Jacob.Fn make_dev_alias .
349f14b89faSDima Dorfman.Pp
350f14b89faSDima DorfmanThe
35144c63b64SDima Dorfman.Fn dev_depends
352f14b89faSDima Dorfmanfunction establishes a parent-child relationship between two devices.
353f14b89faSDima DorfmanThe net effect is that a
354f14b89faSDima Dorfman.Fn destroy_dev
355f14b89faSDima Dorfmanof the parent device will also result in the destruction of the
356f14b89faSDima Dorfmanchild device(s),
357f14b89faSDima Dorfmanif any exist.
358f14b89faSDima DorfmanA device may simultaneously be a parent and a child,
359b82af3f5SMike Pritchardso it is possible to build a complete hierarchy.
360fe754649SKonstantin Belousov.Pp
361fe754649SKonstantin BelousovThe
362fe754649SKonstantin Belousov.Fn destroy_dev_sched_cb
363fe754649SKonstantin Belousovfunction schedules execution of the
364fe754649SKonstantin Belousov.Fn destroy_dev
365fe754649SKonstantin Belousovfor the specified
366fe754649SKonstantin Belousov.Fa cdev
367fe754649SKonstantin Belousovin the safe context.
368fe754649SKonstantin BelousovAfter
369fe754649SKonstantin Belousov.Fn destroy_dev
370fe754649SKonstantin Belousovis finished, and if the supplied
371fe754649SKonstantin Belousov.Fa cb
37295adbc95SJaakko Heinonenis not
37395adbc95SJaakko Heinonen.Dv NULL ,
37495adbc95SJaakko Heinonenthe callback
375fe754649SKonstantin Belousov.Fa cb
376fe754649SKonstantin Belousovis called, with argument
377fe754649SKonstantin Belousov.Fa arg .
378fe754649SKonstantin BelousovThe
379fe754649SKonstantin Belousov.Fn destroy_dev_sched
380fe754649SKonstantin Belousovfunction is the same as
381fe754649SKonstantin Belousov.Bd -literal -offset indent
3823035649eSPawel Jakub Dawidekdestroy_dev_sched_cb(cdev, NULL, NULL);
383e10c1be4SUlrich Spörlein.Ed
384fe754649SKonstantin Belousov.Pp
385fe754649SKonstantin BelousovThe
386fe754649SKonstantin Belousov.Fn d_close
387fe754649SKonstantin Belousovdriver method cannot call
388fe754649SKonstantin Belousov.Fn destroy_dev
389580a4587SAndrey V. Elsukovdirectly.
390580a4587SAndrey V. ElsukovDoing so causes deadlock when
391fe754649SKonstantin Belousov.Fn destroy_dev
392fe754649SKonstantin Belousovwaits for all threads to leave the driver methods.
393fe754649SKonstantin BelousovAlso, because
394fe754649SKonstantin Belousov.Fn destroy_dev
395fe754649SKonstantin Belousovsleeps, no non-sleepable locks may be held over the call.
396fe754649SKonstantin BelousovThe
397fe754649SKonstantin Belousov.Fn destroy_dev_sched
398fe754649SKonstantin Belousovfamily of functions overcome these issues.
399fe754649SKonstantin Belousov.Pp
400fe754649SKonstantin BelousovThe device driver may call the
401fe754649SKonstantin Belousov.Fn destroy_dev_drain
402fe754649SKonstantin Belousovfunction to wait until all devices that have supplied
403fe754649SKonstantin Belousov.Fa csw
404580a4587SAndrey V. Elsukovas cdevsw, are destroyed.
405580a4587SAndrey V. ElsukovThis is useful when driver knows that
406fe754649SKonstantin Belousov.Fn destroy_dev_sched
407fe754649SKonstantin Belousovis called for all instantiated devices, but need to postpone module
408fe754649SKonstantin Belousovunload until
409fe754649SKonstantin Belousov.Fn destroy_dev
410fe754649SKonstantin Belousovis actually finished for all of them.
411f36575b5SJaakko Heinonen.Sh RETURN VALUES
412f36575b5SJaakko HeinonenIf successful,
41348ce5d4cSKonstantin Belousov.Fn make_dev_s
41448ce5d4cSKonstantin Belousovand
415f36575b5SJaakko Heinonen.Fn make_dev_p
41648ce5d4cSKonstantin Belousovwill return 0, otherwise they will return an error.
417f36575b5SJaakko HeinonenIf successful,
418f36575b5SJaakko Heinonen.Fn make_dev_credf
419f36575b5SJaakko Heinonenwill return a valid
420f36575b5SJaakko Heinonen.Fa cdev
421f36575b5SJaakko Heinonenpointer, otherwise it will return
422f36575b5SJaakko Heinonen.Dv NULL .
423f36575b5SJaakko Heinonen.Sh ERRORS
424f36575b5SJaakko HeinonenThe
42548ce5d4cSKonstantin Belousov.Fn make_dev_s ,
426f36575b5SJaakko Heinonen.Fn make_dev_p
4278137364fSAndrey V. Elsukovand
4288137364fSAndrey V. Elsukov.Fn make_dev_alias_p
42948ce5d4cSKonstantin Belousovcalls will fail and the device will be not registered if:
430f36575b5SJaakko Heinonen.Bl -tag -width Er
431f36575b5SJaakko Heinonen.It Bq Er ENOMEM
432f36575b5SJaakko HeinonenThe
433f36575b5SJaakko Heinonen.Dv MAKEDEV_NOWAIT
434353429bfSJaakko Heinonenflag was specified and a memory allocation request could not be satisfied.
435f36575b5SJaakko Heinonen.It Bq Er ENAMETOOLONG
436f36575b5SJaakko HeinonenThe
437f36575b5SJaakko Heinonen.Dv MAKEDEV_CHECKNAME
438353429bfSJaakko Heinonenflag was specified and the provided device name is longer than
439f36575b5SJaakko Heinonen.Dv SPECNAMELEN .
440f36575b5SJaakko Heinonen.It Bq Er EINVAL
441f36575b5SJaakko HeinonenThe
442f36575b5SJaakko Heinonen.Dv MAKEDEV_CHECKNAME
443353429bfSJaakko Heinonenflag was specified and the provided device name is empty, contains a
444f36575b5SJaakko Heinonen.Qq \&.
445f36575b5SJaakko Heinonenor
446f36575b5SJaakko Heinonen.Qq ..
447f36575b5SJaakko Heinonenpath component or ends with
448f36575b5SJaakko Heinonen.Ql / .
449b1e1f725SJaakko Heinonen.It Bq Er EINVAL
450b1e1f725SJaakko HeinonenThe
451b1e1f725SJaakko Heinonen.Dv MAKEDEV_CHECKNAME
452b1e1f725SJaakko Heinonenflag was specified and the provided device name contains invalid characters.
453f36575b5SJaakko Heinonen.It Bq Er EEXIST
454f36575b5SJaakko HeinonenThe
455f36575b5SJaakko Heinonen.Dv MAKEDEV_CHECKNAME
456353429bfSJaakko Heinonenflag was specified and the provided device name already exists.
457f36575b5SJaakko Heinonen.El
458e07f1d5fSHiten Pandya.Sh SEE ALSO
459fe754649SKonstantin Belousov.Xr devctl 4 ,
460*1a720cbeSAlexander Ziaee.Xr devfs 4 ,
461580a4587SAndrey V. Elsukov.Xr dev_clone 9
46294b1839dSChris Costello.Sh HISTORY
46394b1839dSChris CostelloThe
46494b1839dSChris Costello.Fn make_dev
46594b1839dSChris Costelloand
466bd00dbfaSBruce Evans.Fn destroy_dev
46794b1839dSChris Costellofunctions first appeared in
46894b1839dSChris Costello.Fx 4.0 .
469792b2369SMatt JacobThe function
470792b2369SMatt Jacob.Fn make_dev_alias
471792b2369SMatt Jacobfirst appeared in
472792b2369SMatt Jacob.Fx 4.1 .
473f14b89faSDima DorfmanThe function
47444c63b64SDima Dorfman.Fn dev_depends
475f14b89faSDima Dorfmanfirst appeared in
476f14b89faSDima Dorfman.Fx 5.0 .
477fe754649SKonstantin BelousovThe functions
478fe754649SKonstantin Belousov.Fn make_dev_credf ,
479fe754649SKonstantin Belousov.Fn destroy_dev_sched ,
480fe754649SKonstantin Belousov.Fn destroy_dev_sched_cb
481fe754649SKonstantin Belousovfirst appeared in
482fe754649SKonstantin Belousov.Fx 7.0 .
483f36575b5SJaakko HeinonenThe function
484f36575b5SJaakko Heinonen.Fn make_dev_p
485f36575b5SJaakko Heinonenfirst appeared in
486f36575b5SJaakko Heinonen.Fx 8.2 .
48748ce5d4cSKonstantin BelousovThe function
48848ce5d4cSKonstantin Belousov.Fn make_dev_s
48948ce5d4cSKonstantin Belousovfirst appeared in
49048ce5d4cSKonstantin Belousov.Fx 11.0 .
491