aboutsummaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2017-10-01 11:17:30 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2017-10-01 11:17:30 +0000
commit68b2efbd3b74f0d45bbbf07cef5408e455eefbd1 (patch)
tree14e5dbe58f0a071e4ab082b9d442ea637565da94 /sys/dev
parent21811c24c6fa428ec9e0b5e039d9b85f102ce96a (diff)
Notes
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/smbus/smb.c68
1 files changed, 17 insertions, 51 deletions
diff --git a/sys/dev/smbus/smb.c b/sys/dev/smbus/smb.c
index 5f6eff039628..262973340b20 100644
--- a/sys/dev/smbus/smb.c
+++ b/sys/dev/smbus/smb.c
@@ -47,9 +47,7 @@
struct smb_softc {
device_t sc_dev;
- int sc_count; /* >0 if device opened */
struct cdev *sc_devnode;
- struct mtx sc_lock;
};
static void smb_identify(driver_t *driver, device_t parent);
@@ -78,15 +76,11 @@ static driver_t smb_driver = {
sizeof(struct smb_softc),
};
-static d_open_t smbopen;
-static d_close_t smbclose;
static d_ioctl_t smbioctl;
static struct cdevsw smb_cdevsw = {
.d_version = D_VERSION,
.d_flags = D_TRACKCLOSE,
- .d_open = smbopen,
- .d_close = smbclose,
.d_ioctl = smbioctl,
.d_name = "smb",
};
@@ -112,59 +106,31 @@ smb_probe(device_t dev)
static int
smb_attach(device_t dev)
{
- struct smb_softc *sc = device_get_softc(dev);
- int unit;
-
- unit = device_get_unit(dev);
- sc->sc_dev = dev;
+ struct smb_softc *sc;
+ struct make_dev_args mda;
+ int error;
- sc->sc_devnode = make_dev(&smb_cdevsw, unit, UID_ROOT, GID_WHEEL,
- 0600, "smb%d", unit);
- sc->sc_devnode->si_drv1 = sc;
- mtx_init(&sc->sc_lock, device_get_nameunit(dev), NULL, MTX_DEF);
+ sc = device_get_softc(dev);
+ sc->sc_dev = dev;
- return (0);
+ make_dev_args_init(&mda);
+ mda.mda_devsw = &smb_cdevsw;
+ mda.mda_unit = device_get_unit(dev);
+ mda.mda_uid = UID_ROOT;
+ mda.mda_gid = GID_WHEEL;
+ mda.mda_mode = 0600;
+ mda.mda_si_drv1 = sc;
+ error = make_dev_s(&mda, &sc->sc_devnode, "smb%d", mda.mda_unit);
+ return (error);
}
static int
smb_detach(device_t dev)
{
- struct smb_softc *sc = (struct smb_softc *)device_get_softc(dev);
-
- if (sc->sc_devnode)
- destroy_dev(sc->sc_devnode);
- mtx_destroy(&sc->sc_lock);
-
- return (0);
-}
-
-static int
-smbopen(struct cdev *dev, int flags, int fmt, struct thread *td)
-{
- struct smb_softc *sc = dev->si_drv1;
-
- mtx_lock(&sc->sc_lock);
- if (sc->sc_count != 0) {
- mtx_unlock(&sc->sc_lock);
- return (EBUSY);
- }
-
- sc->sc_count++;
- mtx_unlock(&sc->sc_lock);
-
- return (0);
-}
-
-static int
-smbclose(struct cdev *dev, int flags, int fmt, struct thread *td)
-{
- struct smb_softc *sc = dev->si_drv1;
-
- mtx_lock(&sc->sc_lock);
- KASSERT(sc->sc_count == 1, ("device not busy"));
- sc->sc_count--;
- mtx_unlock(&sc->sc_lock);
+ struct smb_softc *sc;
+ sc = device_get_softc(dev);
+ destroy_dev(sc->sc_devnode);
return (0);
}