Remove the distinction between device minor and unit numbers.

Even though we got rid of device major numbers some time ago, device
drivers still need to provide unique device minor numbers to make_dev().
These numbers are only used inside the kernel. They are not related to
device major and minor numbers which are visible in devfs. These are
actually based on the inode number of the device.

It would eventually be nice to remove minor numbers entirely, but we
don't want to be too agressive here.

Because the 8-15 bits of the device number field (si_drv0) are still
reserved for the major number, there is no 1:1 mapping of the device
minor and unit numbers. Because this is now unused, remove the
restrictions on these numbers.

The MAXMAJOR definition was actually used for two purposes. It was used
to convert both the userspace and kernelspace device numbers to their
major/minor pair, which is why it is now named UMINORMASK.

minor2unit() and unit2minor() have now become useless. Both minor() and
dev2unit() now serve the same purpose. We should eventually remove some
of them, at least turning them into macro's. If devfs would become
completely minor number unaware, we could consider using si_drv0 directly,
just like si_drv1 and si_drv2.

Approved by:	philip (mentor)
This commit is contained in:
Ed Schouten 2008-05-29 12:50:46 +00:00
parent 9622e84fcf
commit 06d425f92e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=179413
6 changed files with 14 additions and 17 deletions

View File

@ -277,7 +277,7 @@ upd7210attach(struct upd7210 *u)
struct cdev *dev;
if (units == NULL)
units = new_unrhdr(0, minor2unit(MAXMINOR), NULL);
units = new_unrhdr(0, INT_MAX, NULL);
u->unit = alloc_unr(units);
mtx_init(&u->mutex, "gpib", NULL, MTX_DEF);
u->cdev = make_dev(&gpib_l_cdevsw, u->unit,

View File

@ -15,6 +15,7 @@ __FBSDID("$FreeBSD$");
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/limits.h>
#include <sys/malloc.h>
#include <sys/ctype.h>
#include <sys/sbuf.h>
@ -298,7 +299,7 @@ static void
led_drvinit(void *unused)
{
led_unit = new_unrhdr(0, minor2unit(MAXMINOR), NULL);
led_unit = new_unrhdr(0, INT_MAX, NULL);
mtx_init(&led_mtx, "LED mtx", NULL, MTX_DEF);
sx_init(&led_sx, "LED sx");
callout_init(&led_ch, CALLOUT_MPSAFE);

View File

@ -64,6 +64,7 @@
#include <sys/fcntl.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
#include <sys/limits.h>
#include <sys/linker.h>
#include <sys/lock.h>
#include <sys/malloc.h>
@ -1234,7 +1235,7 @@ g_md_init(struct g_class *mp __unused)
md_preloaded(ptr, len);
sx_xunlock(&md_sx);
}
status_dev = make_dev(&mdctl_cdevsw, MAXMINOR, UID_ROOT, GID_WHEEL,
status_dev = make_dev(&mdctl_cdevsw, INT_MAX, UID_ROOT, GID_WHEEL,
0600, MDCTL_NAME);
g_topology_lock();
}

View File

@ -88,7 +88,7 @@ static void
g_dev_init(struct g_class *mp)
{
unithdr = new_unrhdr(0, minor2unit(MAXMINOR), NULL);
unithdr = new_unrhdr(0, INT_MAX, NULL);
}
void

View File

@ -501,7 +501,7 @@ minor(struct cdev *x)
{
if (x == NULL)
return NODEV;
return(x->si_drv0 & MAXMINOR);
return (x->si_drv0);
}
int
@ -510,23 +510,21 @@ dev2unit(struct cdev *x)
if (x == NULL)
return NODEV;
return (minor2unit(minor(x)));
return (x->si_drv0);
}
u_int
minor2unit(u_int _minor)
{
KASSERT((_minor & ~MAXMINOR) == 0, ("Illegal minor %x", _minor));
return ((_minor & 0xff) | ((_minor >> 8) & 0xffff00));
return (_minor);
}
int
unit2minor(int unit)
{
KASSERT(unit <= 0xffffff, ("Invalid unit (%d) in unit2minor", unit));
return ((unit & 0xff) | ((unit << 8) & ~0xffff));
return (unit);
}
static void
@ -580,16 +578,18 @@ newdev(struct cdevsw *csw, int y, struct cdev *si)
return (si);
}
#define UMINORMASK 0xffff00ffU
int
uminor(dev_t dev)
{
return (dev & MAXMINOR);
return (dev & UMINORMASK);
}
int
umajor(dev_t dev)
{
return ((dev & ~MAXMINOR) >> 8);
return ((dev & ~UMINORMASK) >> 8);
}
static void
@ -697,9 +697,6 @@ make_dev_credv(int flags, struct cdevsw *devsw, int minornr,
struct cdev *dev;
int i;
KASSERT((minornr & ~MAXMINOR) == 0,
("Invalid minor (0x%x) in make_dev", minornr));
dev = devfs_alloc();
dev_lock();
prep_cdevsw(devsw);

View File

@ -223,8 +223,6 @@ struct cdevsw {
#define NUMCDEVSW 256
#define MAXMINOR 0xffff00ffU
struct module;
struct devsw_module_data {