Add a new sysinit SI_SUB_DEVFS. Devfs hooks into the kernel at SI_ORDER_FIRST,

and devices can be created anytime after that.

Print a warning if an atttempt is made to create a device too early.
This commit is contained in:
Mike Smith 2002-01-09 04:58:49 +00:00
parent fdba8cf430
commit a7489fe56f
3 changed files with 21 additions and 2 deletions

View File

@ -437,6 +437,6 @@ devfs_init(void *junk)
devfs_present = 1;
}
SYSINIT(devfs, SI_SUB_DRIVERS, SI_ORDER_FIRST, devfs_init, NULL);
SYSINIT(devfs, SI_SUB_DEVFS, SI_ORDER_FIRST, devfs_init, NULL);
#endif

View File

@ -71,6 +71,8 @@ devfs_create_t *devfs_create_hook;
devfs_destroy_t *devfs_destroy_hook;
int devfs_present;
static int ready_for_devs;
static int free_devt;
SYSCTL_INT(_debug, OID_AUTO, free_devt, CTLFLAG_RW, &free_devt, 0, "");
@ -288,6 +290,12 @@ make_dev(struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, int perms, const
KASSERT(umajor(makeudev(devsw->d_maj, minor)) == devsw->d_maj,
("Invalid minor (%d) in make_dev", minor));
if (!ready_for_devs) {
printf("WARNING: Driver mistake: make_dev(%s) called before SI_SUB_DRIVERS\n",
fmt);
/* XXX panic here once drivers are cleaned up */
}
dev = makedev(devsw->d_maj, minor);
if (dev->si_flags & SI_NAMED) {
printf( "WARNING: Driver mistake: repeat make_dev(\"%s\")\n",
@ -454,4 +462,14 @@ sysctl_devname(SYSCTL_HANDLER_ARGS)
SYSCTL_PROC(_kern, OID_AUTO, devname, CTLTYPE_OPAQUE|CTLFLAG_RW|CTLFLAG_ANYBODY,
NULL, 0, sysctl_devname, "", "devname(3) handler");
/*
* Set ready_for_devs; prior to this point, device creation is not allowed.
*/
static void
dev_set_ready(void *junk)
{
ready_for_devs = 1;
}
SYSINIT(dev_ready, SI_SUB_DEVFS, SI_ORDER_FIRST, dev_set_ready, NULL);

View File

@ -130,6 +130,7 @@ enum sysinit_sub_id {
SI_SUB_MBUF = 0x2700000, /* mbuf subsystem */
SI_SUB_INTR = 0x2800000, /* interrupt threads */
SI_SUB_SOFTINTR = 0x2800001, /* start soft interrupt thread */
SI_SUB_DEVFS = 0x2F00000, /* devfs ready for devices */
SI_SUB_INIT_IF = 0x3000000, /* prep for net interfaces */
SI_SUB_DRIVERS = 0x3100000, /* Let Drivers initialize */
SI_SUB_CONFIGURE = 0x3800000, /* Configure devices */