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.\" 27fe754649SKonstantin Belousov.Dd September 8, 2008 2894b1839dSChris Costello.Os 2994b1839dSChris Costello.Dt MAKE_DEV 9 3094b1839dSChris Costello.Sh NAME 3194b1839dSChris Costello.Nm make_dev , 32fe754649SKonstantin Belousov.Nm make_dev_cred , 33fe754649SKonstantin Belousov.Nm make_dev_credf , 34f14b89faSDima Dorfman.Nm make_dev_alias , 35f14b89faSDima Dorfman.Nm destroy_dev , 36fe754649SKonstantin Belousov.Nm destroy_dev_sched , 37fe754649SKonstantin Belousov.Nm destroy_dev_sched_cb , 38fe754649SKonstantin Belousov.Nm destroy_dev_drain , 3944c63b64SDima Dorfman.Nm dev_depends 40e3718e31SRuslan Ermilov.Nd manage 41c97dc39fSChristian Brueffer.Vt cdev Ns 's 42e3718e31SRuslan Ermilovand DEVFS registration for devices 4394b1839dSChris Costello.Sh SYNOPSIS 44212c98aaSBruce Evans.In sys/param.h 4532eef9aeSRuslan Ermilov.In sys/conf.h 46097fcfebSWarner Losh.Ft struct cdev * 47edde8745SEd Schouten.Fn make_dev "struct cdevsw *cdevsw" "int unit" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ... 48097fcfebSWarner Losh.Ft struct cdev * 49edde8745SEd Schouten.Fn make_dev_cred "struct cdevsw *cdevsw" "int unit" "struct ucred *cr" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ... 50fe754649SKonstantin Belousov.Ft struct cdev * 51edde8745SEd Schouten.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" ... 52fe754649SKonstantin Belousov.Ft struct cdev * 5374c9ea0cSJohn-Mark Gurney.Fn make_dev_alias "struct cdev *pdev" "const char *fmt" ... 5494b1839dSChris Costello.Ft void 55097fcfebSWarner Losh.Fn destroy_dev "struct cdev *dev" 56f14b89faSDima Dorfman.Ft void 57fe754649SKonstantin Belousov.Fn destroy_dev_sched "struct cdev *dev" 58fe754649SKonstantin Belousov.Ft void 59fe754649SKonstantin Belousov.Fn destroy_dev_sched_cb "struct cdev *dev" "void (*cb)(void *)" "void *arg" 60fe754649SKonstantin Belousov.Ft void 61fe754649SKonstantin Belousov.Fn destroy_dev_drain "struct cdevsw *csw" 62fe754649SKonstantin Belousov.Ft void 63097fcfebSWarner Losh.Fn dev_depends "struct cdev *pdev" "struct cdev *cdev" 6494b1839dSChris Costello.Sh DESCRIPTION 6594b1839dSChris CostelloThe 66fe754649SKonstantin Belousov.Fn make_dev_credf 6794b1839dSChris Costellofunction creates a 68c97dc39fSChristian Brueffer.Fa cdev 69a0942a60SHiten Pandyastructure for a new device. 70fe754649SKonstantin BelousovIt also notifies 71fe754649SKonstantin Belousov.Xr devfs 5 72fe754649SKonstantin Belousovof the presence of the new device, that causes corresponding nodes 73fe754649SKonstantin Belousovto be created. 74fe754649SKonstantin BelousovBesides this, a 75fe754649SKonstantin Belousov.Xr devctl 4 76fe754649SKonstantin Belousovnotification is sent. 77a0942a60SHiten PandyaThe device will be owned by 7894b1839dSChris Costello.Va uid , 7994b1839dSChris Costellowith the group ownership as 801dfbd9c2SWarner Losh.Va gid . 811dfbd9c2SWarner LoshThe name is the expansion of 821dfbd9c2SWarner Losh.Va fmt 831dfbd9c2SWarner Loshand following arguments as 841dfbd9c2SWarner Losh.Xr printf 9 851dfbd9c2SWarner Loshwould print it. 861dfbd9c2SWarner LoshThe name determines its path under 871dfbd9c2SWarner Losh.Pa /dev 881dfbd9c2SWarner Loshor other 891dfbd9c2SWarner Losh.Xr devfs 5 901dfbd9c2SWarner Loshmount point and may contain slash 911dfbd9c2SWarner Losh.Ql / 921dfbd9c2SWarner Loshcharacters to denote subdirectories. 9394b1839dSChris CostelloThe permissions of the file specified in 9494b1839dSChris Costello.Va perms 9594b1839dSChris Costelloare defined in 96fe08efe6SRuslan Ermilov.In sys/stat.h : 9794b1839dSChris Costello.Pp 9894b1839dSChris Costello.Bd -literal -offset indent -compact 9994b1839dSChris Costello#define S_IRWXU 0000700 /* RWX mask for owner */ 10094b1839dSChris Costello#define S_IRUSR 0000400 /* R for owner */ 10194b1839dSChris Costello#define S_IWUSR 0000200 /* W for owner */ 10294b1839dSChris Costello#define S_IXUSR 0000100 /* X for owner */ 10394b1839dSChris Costello 10494b1839dSChris Costello#define S_IRWXG 0000070 /* RWX mask for group */ 10594b1839dSChris Costello#define S_IRGRP 0000040 /* R for group */ 10694b1839dSChris Costello#define S_IWGRP 0000020 /* W for group */ 10794b1839dSChris Costello#define S_IXGRP 0000010 /* X for group */ 10894b1839dSChris Costello 10994b1839dSChris Costello#define S_IRWXO 0000007 /* RWX mask for other */ 11094b1839dSChris Costello#define S_IROTH 0000004 /* R for other */ 11194b1839dSChris Costello#define S_IWOTH 0000002 /* W for other */ 11294b1839dSChris Costello#define S_IXOTH 0000001 /* X for other */ 11394b1839dSChris Costello 11494b1839dSChris Costello#define S_ISUID 0004000 /* set user id on execution */ 11594b1839dSChris Costello#define S_ISGID 0002000 /* set group id on execution */ 11694b1839dSChris Costello#define S_ISVTX 0001000 /* sticky bit */ 11794b1839dSChris Costello#ifndef _POSIX_SOURCE 11894b1839dSChris Costello#define S_ISTXT 0001000 11994b1839dSChris Costello#endif 12094b1839dSChris Costello.Ed 12194b1839dSChris Costello.Pp 12294b1839dSChris CostelloThe 123fe754649SKonstantin Belousov.Va cr 124fe754649SKonstantin Belousovargument specifies credentials that will be stored in the 125fe754649SKonstantin Belousov.Fa si_cred 126fe754649SKonstantin Belousovmember of the initialized 127fe754649SKonstantin Belousov.Fa struct cdev . 128fe754649SKonstantin BelousovThe 129fe754649SKonstantin Belousov.Va flags 130fe754649SKonstantin Belousovargument alters the operation of 131fe754649SKonstantin Belousov.Fn make_dev_credf . 132fe754649SKonstantin BelousovThe following values are currently accepted: 133fe754649SKonstantin Belousov.Pp 134fe754649SKonstantin Belousov.Bd -literal -offset indent -compact 135fe754649SKonstantin BelousovMAKEDEV_REF reference the created device 136fe754649SKonstantin Belousov.Ed 137fe754649SKonstantin Belousov.Pp 138fe754649SKonstantin BelousovThe 139fe754649SKonstantin Belousov.Xr dev_clone 9 140fe754649SKonstantin Belousovevent handler shall specify 141fe754649SKonstantin Belousov.Dv MAKEDEV_REF 142fe754649SKonstantin Belousovflag when creating a device in response to lookup, to avoid race where 143fe754649SKonstantin Belousovthe device created is destroyed immediately after 144fe754649SKonstantin Belousov.Xr devfs_lookup 9 145fe754649SKonstantin Belousovdrops his reference to cdev. 146fe754649SKonstantin Belousov.Pp 147fe754649SKonstantin BelousovThe 148fe754649SKonstantin Belousov.Fn make_dev_cred 149fe754649SKonstantin Belousovfunction is equivalent to the call 150fe754649SKonstantin Belousov.Bd -literal -offset indent 151edde8745SEd Schoutenmake_dev_credf(0, cdevsw, unit, cr, uid, gid, perms, fmt, ...); 152fe754649SKonstantin Belousov.Ed . 153fe754649SKonstantin Belousov.Pp 154fe754649SKonstantin BelousovThe 155fe754649SKonstantin Belousov.Fn make_dev 156fe754649SKonstantin Belousovfunction call is the same as 157fe754649SKonstantin Belousov.Bd -literal -offset indent 158edde8745SEd Schoutenmake_dev_credf(0, cdevsw, unit, NULL, uid, gid, perms, fmt, ...); 159fe754649SKonstantin Belousov.Ed . 160fe754649SKonstantin Belousov.Pp 161fe754649SKonstantin BelousovThe 162792b2369SMatt Jacob.Fn make_dev_alias 163792b2369SMatt Jacobfunction takes the returned 164c97dc39fSChristian Brueffer.Ft cdev 165792b2369SMatt Jacobfrom 166792b2369SMatt Jacob.Fn make_dev 167edf0984dSRuslan Ermilovand makes another (aliased) name for this device. 168edf0984dSRuslan ErmilovIt is an error to call 169792b2369SMatt Jacob.Fn make_dev_alias 170792b2369SMatt Jacobprior to calling 171792b2369SMatt Jacob.Fn make_dev . 172792b2369SMatt Jacob.Pp 173792b2369SMatt JacobThe 1742557913dSJohn-Mark Gurney.Fa cdev 1752557913dSJohn-Mark Gurneyreturned by 1762557913dSJohn-Mark Gurney.Fn make_dev 1772557913dSJohn-Mark Gurneyand 1782557913dSJohn-Mark Gurney.Fn make_dev_alias 1792557913dSJohn-Mark Gurneyhas two fields, 1802557913dSJohn-Mark Gurney.Fa si_drv1 1812557913dSJohn-Mark Gurneyand 1822557913dSJohn-Mark Gurney.Fa si_drv2 , 18377213b87SChristian Bruefferthat are available to store state. 18477213b87SChristian BruefferBoth fields are of type 1852557913dSJohn-Mark Gurney.Ft void * . 1862557913dSJohn-Mark GurneyThese are designed to replace the 187edde8745SEd Schouten.Fa unit 1882557913dSJohn-Mark Gurneyargument to 1892557913dSJohn-Mark Gurney.Fn make_dev . 1902557913dSJohn-Mark Gurney.Pp 1912557913dSJohn-Mark GurneyThe 192bd00dbfaSBruce Evans.Fn destroy_dev 19394b1839dSChris Costellofunction takes the returned 194c97dc39fSChristian Brueffer.Fa cdev 19594b1839dSChris Costellofrom 19694b1839dSChris Costello.Fn make_dev 197edf0984dSRuslan Ermilovand destroys the registration for that device. 198fe754649SKonstantin BelousovThe notification is sent to 199fe754649SKonstantin Belousov.Xr devctl 4 200fe754649SKonstantin Belousovabout the destruction event. 201edf0984dSRuslan ErmilovDo not call 202792b2369SMatt Jacob.Fn destroy_dev 203792b2369SMatt Jacobon devices that were created with 204792b2369SMatt Jacob.Fn make_dev_alias . 205f14b89faSDima Dorfman.Pp 206f14b89faSDima DorfmanThe 20744c63b64SDima Dorfman.Fn dev_depends 208f14b89faSDima Dorfmanfunction establishes a parent-child relationship between two devices. 209f14b89faSDima DorfmanThe net effect is that a 210f14b89faSDima Dorfman.Fn destroy_dev 211f14b89faSDima Dorfmanof the parent device will also result in the destruction of the 212f14b89faSDima Dorfmanchild device(s), 213f14b89faSDima Dorfmanif any exist. 214f14b89faSDima DorfmanA device may simultaneously be a parent and a child, 215b82af3f5SMike Pritchardso it is possible to build a complete hierarchy. 216fe754649SKonstantin Belousov.Pp 217fe754649SKonstantin BelousovThe 218fe754649SKonstantin Belousov.Fn destroy_dev_sched_cb 219fe754649SKonstantin Belousovfunction schedules execution of the 220fe754649SKonstantin Belousov.Fn destroy_dev 221fe754649SKonstantin Belousovfor the specified 222fe754649SKonstantin Belousov.Fa cdev 223fe754649SKonstantin Belousovin the safe context. 224fe754649SKonstantin BelousovAfter 225fe754649SKonstantin Belousov.Fn destroy_dev 226fe754649SKonstantin Belousovis finished, and if the supplied 227fe754649SKonstantin Belousov.Fa cb 228fe754649SKonstantin Belousovis not NULL, the callback 229fe754649SKonstantin Belousov.Fa cb 230fe754649SKonstantin Belousovis called, with argument 231fe754649SKonstantin Belousov.Fa arg . 232fe754649SKonstantin BelousovThe 233fe754649SKonstantin Belousov.Fn destroy_dev_sched 234fe754649SKonstantin Belousovfunction is the same as 235fe754649SKonstantin Belousov.Bd -literal -offset indent 236fe754649SKonstantin Belousovdestroy_dev_sched(cdev, NULL, NULL); 237fe754649SKonstantin Belousov.Ed . 238fe754649SKonstantin Belousov.Pp 239fe754649SKonstantin BelousovThe 240fe754649SKonstantin Belousov.Fn d_close 241fe754649SKonstantin Belousovdriver method cannot call 242fe754649SKonstantin Belousov.Fn destroy_dev 243fe754649SKonstantin Belousovdirectly. Doing so causes deadlock when 244fe754649SKonstantin Belousov.Fn destroy_dev 245fe754649SKonstantin Belousovwaits for all threads to leave the driver methods. 246fe754649SKonstantin BelousovAlso, because 247fe754649SKonstantin Belousov.Fn destroy_dev 248fe754649SKonstantin Belousovsleeps, no non-sleepable locks may be held over the call. 249fe754649SKonstantin BelousovThe 250fe754649SKonstantin Belousov.Fn destroy_dev_sched 251fe754649SKonstantin Belousovfamily of functions overcome these issues. 252fe754649SKonstantin Belousov.Pp 253fe754649SKonstantin BelousovThe device driver may call the 254fe754649SKonstantin Belousov.Fn destroy_dev_drain 255fe754649SKonstantin Belousovfunction to wait until all devices that have supplied 256fe754649SKonstantin Belousov.Fa csw 257fe754649SKonstantin Belousovas cdevsw, are destroyed. This is useful when driver knows that 258fe754649SKonstantin Belousov.Fn destroy_dev_sched 259fe754649SKonstantin Belousovis called for all instantiated devices, but need to postpone module 260fe754649SKonstantin Belousovunload until 261fe754649SKonstantin Belousov.Fn destroy_dev 262fe754649SKonstantin Belousovis actually finished for all of them. 263fe754649SKonstantin Belousov.Pp 264e07f1d5fSHiten Pandya.Sh SEE ALSO 265fe754649SKonstantin Belousov.Xr devctl 4 , 266fe754649SKonstantin Belousov.Xr destroy_dev_drain 9 , 267fe754649SKonstantin Belousov.Xr dev_clone 9 , 268e07f1d5fSHiten Pandya.Xr devfs 5 26994b1839dSChris Costello.Sh HISTORY 27094b1839dSChris CostelloThe 27194b1839dSChris Costello.Fn make_dev 27294b1839dSChris Costelloand 273bd00dbfaSBruce Evans.Fn destroy_dev 27494b1839dSChris Costellofunctions first appeared in 27594b1839dSChris Costello.Fx 4.0 . 276792b2369SMatt JacobThe function 277792b2369SMatt Jacob.Fn make_dev_alias 278792b2369SMatt Jacobfirst appeared in 279792b2369SMatt Jacob.Fx 4.1 . 280f14b89faSDima DorfmanThe function 28144c63b64SDima Dorfman.Fn dev_depends 282f14b89faSDima Dorfmanfirst appeared in 283f14b89faSDima Dorfman.Fx 5.0 . 284fe754649SKonstantin BelousovThe functions 285fe754649SKonstantin Belousov.Fn make_dev_credf , 286fe754649SKonstantin Belousov.Fn destroy_dev_sched , 287fe754649SKonstantin Belousov.Fn destroy_dev_sched_cb 288fe754649SKonstantin Belousovfirst appeared in 289fe754649SKonstantin Belousov.Fx 7.0 . 290