Lines Matching defs: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)));
167 if (dev->si_devsw == NULL && dev->si_refcount == 0) {
168 LIST_REMOVE(dev, si_list);
173 devfs_free(dev);
177 dev_refthread(struct cdev *dev, int *ref)
183 if ((dev->si_flags & SI_ETERNAL) != 0) {
185 return (dev->si_devsw);
188 csw = dev->si_devsw;
190 cdp = cdev2priv(dev);
192 atomic_add_long(&dev->si_threadcount, 1);
206 struct cdev *dev;
210 dev = vp->v_rdev;
211 if (dev == NULL)
213 KASSERT((dev->si_flags & SI_ETERNAL) != 0,
216 csw = dev->si_devsw;
218 *devp = dev;
224 dev = vp->v_rdev;
225 if (dev == NULL) {
229 cdp = cdev2priv(dev);
231 csw = dev->si_devsw;
233 atomic_add_long(&dev->si_threadcount, 1);
237 *devp = dev;
244 dev_relthread(struct cdev *dev, int ref)
250 KASSERT(dev->si_threadcount > 0,
251 ("%s threadcount is wrong", dev->si_name));
252 atomic_subtract_rel_long(&dev->si_threadcount, 1);
337 no_poll(struct cdev *dev __unused, int events, struct thread *td __unused)
346 giant_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
351 dsw = dev_refthread(dev, &ref);
355 retval = dsw->d_gianttrick->d_open(dev, oflags, devtype, td);
357 dev_relthread(dev, ref);
362 giant_fdopen(struct cdev *dev, int oflags, struct thread *td, struct file *fp)
367 dsw = dev_refthread(dev, &ref);
371 retval = dsw->d_gianttrick->d_fdopen(dev, oflags, td, fp);
373 dev_relthread(dev, ref);
378 giant_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
383 dsw = dev_refthread(dev, &ref);
387 retval = dsw->d_gianttrick->d_close(dev, fflag, devtype, td);
389 dev_relthread(dev, ref);
397 struct cdev *dev;
400 dev = bp->bio_dev;
401 dsw = dev_refthread(dev, &ref);
409 dev_relthread(dev, ref);
413 giant_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
418 dsw = dev_refthread(dev, &ref);
422 retval = dsw->d_gianttrick->d_ioctl(dev, cmd, data, fflag, td);
424 dev_relthread(dev, ref);
429 giant_read(struct cdev *dev, struct uio *uio, int ioflag)
434 dsw = dev_refthread(dev, &ref);
438 retval = dsw->d_gianttrick->d_read(dev, uio, ioflag);
440 dev_relthread(dev, ref);
445 giant_write(struct cdev *dev, struct uio *uio, int ioflag)
450 dsw = dev_refthread(dev, &ref);
454 retval = dsw->d_gianttrick->d_write(dev, uio, ioflag);
456 dev_relthread(dev, ref);
461 giant_poll(struct cdev *dev, int events, struct thread *td)
466 dsw = dev_refthread(dev, &ref);
470 retval = dsw->d_gianttrick->d_poll(dev, events, td);
472 dev_relthread(dev, ref);
477 giant_kqfilter(struct cdev *dev, struct knote *kn)
482 dsw = dev_refthread(dev, &ref);
486 retval = dsw->d_gianttrick->d_kqfilter(dev, kn);
488 dev_relthread(dev, ref);
493 giant_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot,
499 dsw = dev_refthread(dev, &ref);
503 retval = dsw->d_gianttrick->d_mmap(dev, offset, paddr, nprot,
506 dev_relthread(dev, ref);
511 giant_mmap_single(struct cdev *dev, vm_ooffset_t *offset, vm_size_t size,
517 dsw = dev_refthread(dev, &ref);
521 retval = dsw->d_gianttrick->d_mmap_single(dev, offset, size, object,
524 dev_relthread(dev, ref);
529 notify(struct cdev *dev, const char *ev, int flags)
538 namelen = strlen(dev->si_name);
543 memcpy(data + sizeof(prefix) - 1, dev->si_name, namelen + 1);
549 notify_create(struct cdev *dev, int flags)
552 notify(dev, "CREATE", flags);
556 notify_destroy(struct cdev *dev)
559 notify(dev, "DESTROY", MAKEDEV_WAITOK);
704 prep_devname(struct cdev *dev, const char *fmt, va_list ap)
711 len = vsnrprintf(dev->si_name, sizeof(dev->si_name), 32, fmt, ap);
712 if (len > sizeof(dev->si_name) - 1)
716 for (from = dev->si_name; *from == '/'; from++)
719 for (to = dev->si_name; *from != '\0'; from++, to++) {
737 if (dev->si_name[0] == '\0')
741 for (s = dev->si_name;;) {
753 if (devfs_dev_exists(dev->si_name) != 0)
771 struct cdev *dev, *dev_new;
792 dev = newdev(&args, dev_new);
793 if ((dev->si_flags & SI_NAMED) == 0) {
794 res = prep_devname(dev, fmt, ap);
799 res, dev->si_name);
801 if (dev == dev_new) {
802 LIST_REMOVE(dev, si_list);
804 devfs_free(dev);
811 dev_refl(dev);
813 dev->si_flags |= SI_ETERNAL;
814 KASSERT(!(dev->si_flags & SI_NAMED),
816 args.mda_devsw->d_name, dev2unit(dev), devtoname(dev)));
817 dev->si_flags |= SI_NAMED;
819 dev->si_cred = crhold(args.mda_cr);
820 dev->si_uid = args.mda_uid;
821 dev->si_gid = args.mda_gid;
822 dev->si_mode = args.mda_mode;
824 devfs_create(dev);
828 notify_create(dev, args.mda_flags);
830 *dres = dev;
869 struct cdev *dev;
874 res = make_dev_credv(0, &dev, devsw, unit, NULL, uid, gid, mode, fmt,
877 KASSERT(res == 0 && dev != NULL,
879 return (dev);
886 struct cdev *dev;
891 res = make_dev_credv(0, &dev, devsw, unit, cr, uid, gid, mode, fmt, ap);
894 KASSERT(res == 0 && dev != NULL,
896 return (dev);
903 struct cdev *dev;
908 res = make_dev_credv(flags, &dev, devsw, unit, cr, uid, gid, mode,
915 return (res == 0 ? dev : NULL);
959 struct cdev *dev;
969 dev = devfs_alloc(flags);
970 if (dev == NULL)
973 dev->si_flags |= SI_ALIAS;
974 error = prep_devname(dev, fmt, ap);
978 "(error=%d, si_name=%s)", error, dev->si_name);
981 devfs_free(dev);
984 dev->si_flags |= SI_NAMED;
985 devfs_create(dev);
986 dev_dependsl(pdev, dev);
990 notify_create(dev, flags);
991 *cdev = dev;
999 struct cdev *dev;
1004 res = make_dev_alias_v(MAKEDEV_WAITOK, &dev, pdev, fmt, ap);
1007 KASSERT(res == 0 && dev != NULL,
1009 return (dev);
1088 destroy_devl(struct cdev *dev)
1095 KASSERT(dev->si_flags & SI_NAMED,
1096 ("WARNING: Driver mistake: destroy_dev on %d\n", dev2unit(dev)));
1097 KASSERT((dev->si_flags & SI_ETERNAL) == 0,
1099 dev2unit(dev)));
1101 cdp = cdev2priv(dev);
1109 dev_refl(dev);
1111 devfs_destroy(dev);
1115 dev->si_flags &= ~SI_NAMED;
1118 if (dev->si_flags & SI_CHILD) {
1119 LIST_REMOVE(dev, si_siblings);
1120 dev->si_flags &= ~SI_CHILD;
1124 while (!LIST_EMPTY(&dev->si_children))
1125 destroy_devl(LIST_FIRST(&dev->si_children));
1128 if (dev->si_flags & SI_CLONELIST) {
1129 LIST_REMOVE(dev, si_clone);
1130 dev->si_flags &= ~SI_CLONELIST;
1133 csw = dev->si_devsw;
1134 dev->si_devsw = NULL; /* already NULL for SI_ALIAS */
1135 while (csw != NULL && csw->d_purge != NULL && dev->si_threadcount) {
1136 csw->d_purge(dev);
1138 if (dev->si_threadcount)
1140 dev->si_threadcount, devtoname(dev));
1142 while (dev->si_threadcount != 0) {
1150 notify_destroy(dev);
1160 dev->si_drv1 = 0;
1161 dev->si_drv2 = 0;
1162 bzero(&dev->__si_u, sizeof(dev->__si_u));
1164 if (!(dev->si_flags & SI_ALIAS)) {
1166 LIST_REMOVE(dev, si_list);
1174 dev->si_flags &= ~SI_ALIAS;
1176 dev->si_refcount--;
1178 if (dev->si_refcount > 0)
1179 LIST_INSERT_HEAD(&dead_cdevsw.d_devs, dev, si_list);
1181 dev_free_devlocked(dev);
1185 delist_dev_locked(struct cdev *dev)
1191 cdp = cdev2priv(dev);
1195 dev_refl(dev);
1196 devfs_destroy(dev);
1197 LIST_FOREACH(child, &dev->si_children, si_siblings)
1201 notify_destroy(dev);
1214 delist_dev(struct cdev *dev)
1219 delist_dev_locked(dev);
1224 destroy_dev(struct cdev *dev)
1229 destroy_devl(dev);
1234 devtoname(struct cdev *dev)
1237 return (dev->si_name);
1301 struct cdev *dev, *ndev, *dl, *de;
1330 LIST_FOREACH(dev, &cd->head, si_clone) {
1331 KASSERT(dev->si_flags & SI_CLONELIST,
1332 ("Dev %p(%s) should be on clonelist", dev, dev->si_name));
1333 u = dev2unit(dev);
1335 *dp = dev;
1342 de = dev;
1345 de = dev;
1348 dl = dev;
1357 dev = newdev(&args, ndev);
1358 if (dev->si_flags & SI_CLONELIST) {
1359 printf("dev %p (%s) is on clonelist\n", dev, dev->si_name);
1361 LIST_FOREACH(dev, &cd->head, si_clone) {
1362 printf("\t%p %s\n", dev, dev->si_name);
1366 KASSERT(!(dev->si_flags & SI_CLONELIST),
1367 ("Dev %p(%s) should not be on clonelist", dev, dev->si_name));
1369 LIST_INSERT_BEFORE(dl, dev, si_clone);
1371 LIST_INSERT_AFTER(de, dev, si_clone);
1373 LIST_INSERT_HEAD(&cd->head, dev, si_clone);
1374 dev->si_flags |= SI_CLONELIST;
1387 struct cdev *dev;
1396 dev = LIST_FIRST(&cd->head);
1397 LIST_REMOVE(dev, si_clone);
1398 KASSERT(dev->si_flags & SI_CLONELIST,
1399 ("Dev %p(%s) should be on clonelist", dev, dev->si_name));
1400 dev->si_flags &= ~SI_CLONELIST;
1401 cp = cdev2priv(dev);
1404 KASSERT(dev->si_flags & SI_NAMED,
1406 (uintmax_t)dev2udev(dev), dev2unit(dev)));
1407 destroy_devl(dev);
1423 struct cdev *dev;
1430 dev = &cp->cdp_c;
1436 destroy_devl(dev);
1438 dev_rel(dev);
1451 destroy_dev_sched_cbl(struct cdev *dev, void (*cb)(void *), void *arg)
1456 cp = cdev2priv(dev);
1461 dev_refl(dev);
1472 destroy_dev_sched_cb(struct cdev *dev, void (*cb)(void *), void *arg)
1476 return (destroy_dev_sched_cbl(dev, cb, arg));
1480 destroy_dev_sched(struct cdev *dev)
1483 return (destroy_dev_sched_cb(dev, NULL, NULL));
1514 struct cdev *dev;
1520 dev = &cdp->cdp_c;
1521 db_printf("%s %p\n", dev->si_name, dev);
1528 dev = (struct cdev *)addr;
1529 cdp = cdev2priv(dev);
1530 db_printf("dev %s ref %d use %ld thr %ld inuse %u fdpriv %p\n",
1531 dev->si_name, dev->si_refcount, dev->si_usecount,
1532 dev->si_threadcount, cdp->cdp_inuse, cdp->cdp_fdpriv.lh_first);
1534 dev->si_devsw, dev->si_drv0, dev->si_drv1, dev->si_drv2);
1535 flags = dev->si_flags;