Lines Matching refs:dev

55 static void destroy_devl(struct cdev *dev);
56 static int destroy_dev_sched_cbl(struct cdev *dev,
140 dev_ref(struct cdev *dev)
145 dev->si_refcount++;
150 dev_refl(struct cdev *dev)
154 dev->si_refcount++;
158 dev_rel(struct cdev *dev)
164 dev->si_refcount--;
165 KASSERT(dev->si_refcount >= 0,
166 ("dev_rel(%s) gave negative count", devtoname(dev)));
168 if (dev->si_usecount == 0 &&
169 (dev->si_flags & SI_CHEAPCLONE) && (dev->si_flags & SI_NAMED))
173 if (dev->si_devsw == NULL && dev->si_refcount == 0) {
174 LIST_REMOVE(dev, si_list);
179 devfs_free(dev);
183 dev_refthread(struct cdev *dev, int *ref)
189 if ((dev->si_flags & SI_ETERNAL) != 0) {
191 return (dev->si_devsw);
194 csw = dev->si_devsw;
196 cdp = cdev2priv(dev);
198 atomic_add_long(&dev->si_threadcount, 1);
212 struct cdev *dev;
216 dev = vp->v_rdev;
217 if (dev == NULL)
219 KASSERT((dev->si_flags & SI_ETERNAL) != 0,
222 csw = dev->si_devsw;
224 *devp = dev;
230 dev = vp->v_rdev;
231 if (dev == NULL) {
235 cdp = cdev2priv(dev);
237 csw = dev->si_devsw;
239 atomic_add_long(&dev->si_threadcount, 1);
243 *devp = dev;
250 dev_relthread(struct cdev *dev, int ref)
256 KASSERT(dev->si_threadcount > 0,
257 ("%s threadcount is wrong", dev->si_name));
258 atomic_subtract_rel_long(&dev->si_threadcount, 1);
343 no_poll(struct cdev *dev __unused, int events, struct thread *td __unused)
352 giant_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
357 dsw = dev_refthread(dev, &ref);
361 retval = dsw->d_gianttrick->d_open(dev, oflags, devtype, td);
363 dev_relthread(dev, ref);
368 giant_fdopen(struct cdev *dev, int oflags, struct thread *td, struct file *fp)
373 dsw = dev_refthread(dev, &ref);
377 retval = dsw->d_gianttrick->d_fdopen(dev, oflags, td, fp);
379 dev_relthread(dev, ref);
384 giant_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
389 dsw = dev_refthread(dev, &ref);
393 retval = dsw->d_gianttrick->d_close(dev, fflag, devtype, td);
395 dev_relthread(dev, ref);
403 struct cdev *dev;
406 dev = bp->bio_dev;
407 dsw = dev_refthread(dev, &ref);
415 dev_relthread(dev, ref);
419 giant_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
424 dsw = dev_refthread(dev, &ref);
428 retval = dsw->d_gianttrick->d_ioctl(dev, cmd, data, fflag, td);
430 dev_relthread(dev, ref);
435 giant_read(struct cdev *dev, struct uio *uio, int ioflag)
440 dsw = dev_refthread(dev, &ref);
444 retval = dsw->d_gianttrick->d_read(dev, uio, ioflag);
446 dev_relthread(dev, ref);
451 giant_write(struct cdev *dev, struct uio *uio, int ioflag)
456 dsw = dev_refthread(dev, &ref);
460 retval = dsw->d_gianttrick->d_write(dev, uio, ioflag);
462 dev_relthread(dev, ref);
467 giant_poll(struct cdev *dev, int events, struct thread *td)
472 dsw = dev_refthread(dev, &ref);
476 retval = dsw->d_gianttrick->d_poll(dev, events, td);
478 dev_relthread(dev, ref);
483 giant_kqfilter(struct cdev *dev, struct knote *kn)
488 dsw = dev_refthread(dev, &ref);
492 retval = dsw->d_gianttrick->d_kqfilter(dev, kn);
494 dev_relthread(dev, ref);
499 giant_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot,
505 dsw = dev_refthread(dev, &ref);
509 retval = dsw->d_gianttrick->d_mmap(dev, offset, paddr, nprot,
512 dev_relthread(dev, ref);
517 giant_mmap_single(struct cdev *dev, vm_ooffset_t *offset, vm_size_t size,
523 dsw = dev_refthread(dev, &ref);
527 retval = dsw->d_gianttrick->d_mmap_single(dev, offset, size, object,
530 dev_relthread(dev, ref);
535 notify(struct cdev *dev, const char *ev, int flags)
544 namelen = strlen(dev->si_name);
549 memcpy(data + sizeof(prefix) - 1, dev->si_name, namelen + 1);
555 notify_create(struct cdev *dev, int flags)
558 notify(dev, "CREATE", flags);
562 notify_destroy(struct cdev *dev)
565 notify(dev, "DESTROY", MAKEDEV_WAITOK);
689 prep_devname(struct cdev *dev, const char *fmt, va_list ap)
696 len = vsnrprintf(dev->si_name, sizeof(dev->si_name), 32, fmt, ap);
697 if (len > sizeof(dev->si_name) - 1)
701 for (from = dev->si_name; *from == '/'; from++)
704 for (to = dev->si_name; *from != '\0'; from++, to++) {
722 if (dev->si_name[0] == '\0')
726 for (s = dev->si_name;;) {
738 if (devfs_dev_exists(dev->si_name) != 0)
756 struct cdev *dev, *dev_new;
777 dev = newdev(&args, dev_new);
778 if ((dev->si_flags & SI_NAMED) == 0) {
779 res = prep_devname(dev, fmt, ap);
784 res, dev->si_name);
786 if (dev == dev_new) {
787 LIST_REMOVE(dev, si_list);
789 devfs_free(dev);
796 dev_refl(dev);
798 dev->si_flags |= SI_ETERNAL;
799 if (dev->si_flags & SI_CHEAPCLONE &&
800 dev->si_flags & SI_NAMED) {
807 *dres = dev;
810 KASSERT(!(dev->si_flags & SI_NAMED),
812 args.mda_devsw->d_name, dev2unit(dev), devtoname(dev)));
813 dev->si_flags |= SI_NAMED;
815 dev->si_cred = crhold(args.mda_cr);
816 dev->si_uid = args.mda_uid;
817 dev->si_gid = args.mda_gid;
818 dev->si_mode = args.mda_mode;
820 devfs_create(dev);
824 notify_create(dev, args.mda_flags);
826 *dres = dev;
865 struct cdev *dev;
870 res = make_dev_credv(0, &dev, devsw, unit, NULL, uid, gid, mode, fmt,
873 KASSERT(res == 0 && dev != NULL,
875 return (dev);
882 struct cdev *dev;
887 res = make_dev_credv(0, &dev, devsw, unit, cr, uid, gid, mode, fmt, ap);
890 KASSERT(res == 0 && dev != NULL,
892 return (dev);
899 struct cdev *dev;
904 res = make_dev_credv(flags, &dev, devsw, unit, cr, uid, gid, mode,
911 return (res == 0 ? dev : NULL);
955 struct cdev *dev;
965 dev = devfs_alloc(flags);
966 if (dev == NULL)
969 dev->si_flags |= SI_ALIAS;
970 error = prep_devname(dev, fmt, ap);
974 "(error=%d, si_name=%s)", error, dev->si_name);
977 devfs_free(dev);
980 dev->si_flags |= SI_NAMED;
981 devfs_create(dev);
982 dev_dependsl(pdev, dev);
986 notify_create(dev, flags);
987 *cdev = dev;
995 struct cdev *dev;
1000 res = make_dev_alias_v(MAKEDEV_WAITOK, &dev, pdev, fmt, ap);
1003 KASSERT(res == 0 && dev != NULL,
1005 return (dev);
1084 destroy_devl(struct cdev *dev)
1091 KASSERT(dev->si_flags & SI_NAMED,
1092 ("WARNING: Driver mistake: destroy_dev on %d\n", dev2unit(dev)));
1093 KASSERT((dev->si_flags & SI_ETERNAL) == 0,
1095 dev2unit(dev)));
1097 cdp = cdev2priv(dev);
1105 dev_refl(dev);
1107 devfs_destroy(dev);
1111 dev->si_flags &= ~SI_NAMED;
1114 if (dev->si_flags & SI_CHILD) {
1115 LIST_REMOVE(dev, si_siblings);
1116 dev->si_flags &= ~SI_CHILD;
1120 while (!LIST_EMPTY(&dev->si_children))
1121 destroy_devl(LIST_FIRST(&dev->si_children));
1124 if (dev->si_flags & SI_CLONELIST) {
1125 LIST_REMOVE(dev, si_clone);
1126 dev->si_flags &= ~SI_CLONELIST;
1129 csw = dev->si_devsw;
1130 dev->si_devsw = NULL; /* already NULL for SI_ALIAS */
1131 while (csw != NULL && csw->d_purge != NULL && dev->si_threadcount) {
1132 csw->d_purge(dev);
1134 if (dev->si_threadcount)
1136 dev->si_threadcount, devtoname(dev));
1138 while (dev->si_threadcount != 0) {
1146 notify_destroy(dev);
1156 dev->si_drv1 = 0;
1157 dev->si_drv2 = 0;
1158 bzero(&dev->__si_u, sizeof(dev->__si_u));
1160 if (!(dev->si_flags & SI_ALIAS)) {
1162 LIST_REMOVE(dev, si_list);
1170 dev->si_flags &= ~SI_ALIAS;
1172 dev->si_refcount--;
1174 if (dev->si_refcount > 0)
1175 LIST_INSERT_HEAD(&dead_cdevsw.d_devs, dev, si_list);
1177 dev_free_devlocked(dev);
1181 delist_dev_locked(struct cdev *dev)
1187 cdp = cdev2priv(dev);
1191 dev_refl(dev);
1192 devfs_destroy(dev);
1193 LIST_FOREACH(child, &dev->si_children, si_siblings)
1197 notify_destroy(dev);
1210 delist_dev(struct cdev *dev)
1215 delist_dev_locked(dev);
1220 destroy_dev(struct cdev *dev)
1225 destroy_devl(dev);
1230 devtoname(struct cdev *dev)
1233 return (dev->si_name);
1297 struct cdev *dev, *ndev, *dl, *de;
1326 LIST_FOREACH(dev, &cd->head, si_clone) {
1327 KASSERT(dev->si_flags & SI_CLONELIST,
1328 ("Dev %p(%s) should be on clonelist", dev, dev->si_name));
1329 u = dev2unit(dev);
1331 *dp = dev;
1338 de = dev;
1341 de = dev;
1344 dl = dev;
1353 dev = newdev(&args, ndev);
1354 if (dev->si_flags & SI_CLONELIST) {
1355 printf("dev %p (%s) is on clonelist\n", dev, dev->si_name);
1357 LIST_FOREACH(dev, &cd->head, si_clone) {
1358 printf("\t%p %s\n", dev, dev->si_name);
1362 KASSERT(!(dev->si_flags & SI_CLONELIST),
1363 ("Dev %p(%s) should not be on clonelist", dev, dev->si_name));
1365 LIST_INSERT_BEFORE(dl, dev, si_clone);
1367 LIST_INSERT_AFTER(de, dev, si_clone);
1369 LIST_INSERT_HEAD(&cd->head, dev, si_clone);
1370 dev->si_flags |= SI_CLONELIST;
1383 struct cdev *dev;
1392 dev = LIST_FIRST(&cd->head);
1393 LIST_REMOVE(dev, si_clone);
1394 KASSERT(dev->si_flags & SI_CLONELIST,
1395 ("Dev %p(%s) should be on clonelist", dev, dev->si_name));
1396 dev->si_flags &= ~SI_CLONELIST;
1397 cp = cdev2priv(dev);
1400 KASSERT(dev->si_flags & SI_NAMED,
1402 (uintmax_t)dev2udev(dev), dev2unit(dev)));
1403 destroy_devl(dev);
1419 struct cdev *dev;
1426 dev = &cp->cdp_c;
1432 destroy_devl(dev);
1434 dev_rel(dev);
1447 destroy_dev_sched_cbl(struct cdev *dev, void (*cb)(void *), void *arg)
1452 cp = cdev2priv(dev);
1457 dev_refl(dev);
1468 destroy_dev_sched_cb(struct cdev *dev, void (*cb)(void *), void *arg)
1472 return (destroy_dev_sched_cbl(dev, cb, arg));
1476 destroy_dev_sched(struct cdev *dev)
1479 return (destroy_dev_sched_cb(dev, NULL, NULL));
1510 struct cdev *dev;
1516 dev = &cdp->cdp_c;
1517 db_printf("%s %p\n", dev->si_name, dev);
1524 dev = (struct cdev *)addr;
1525 cdp = cdev2priv(dev);
1526 db_printf("dev %s ref %d use %ld thr %ld inuse %u fdpriv %p\n",
1527 dev->si_name, dev->si_refcount, dev->si_usecount,
1528 dev->si_threadcount, cdp->cdp_inuse, cdp->cdp_fdpriv.lh_first);
1530 dev->si_devsw, dev->si_drv0, dev->si_drv1, dev->si_drv2);
1531 flags = dev->si_flags;