Date: Fri, 16 Aug 2002 18:08:31 -0500 From: dmk <gh@over-yonder.net> To: Robert Watson <rwatson@freebsd.org> Cc: freebsd-current@freebsd.org Subject: Re: emulators/rtc and vmware2 Message-ID: <20020816230831.GD35400@over-yonder.net> In-Reply-To: <Pine.NEB.3.96L.1020815133521.8976D-100000@fledge.watson.org> References: <20020815121105.GA35400@over-yonder.net> <Pine.NEB.3.96L.1020815133521.8976D-100000@fledge.watson.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--mojUlQ0s9EVzWg2t
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Thu, 15 Aug 2002, dmk wrote:
>
> Is anybody successfully using the port emulators/rtc with vmware2 on
> -current?
[...]
On Thu, Aug 15, 2002 at 01:36:46PM -0400 Robert Watson wrote:
> My recollection is that the problem relates to calling make_dev() from the
> attach routine, and attach from the open call, and of course you can't
> open before you make_dev with devfs. Someone needs to restructure the
> driver to match some our other pseudo-device drivers where the device is
> properly created as part of module initialization.
[...]
> Robert N M Watson FreeBSD Core Team, TrustedBSD Projects
> robert@fledge.watson.org Network Associates Laboratories
The attached diff effectively restructures the rtc device driver to
perform the make_dev() at module load. The driver may have problems, but
it does work, and, unlike the first diff, doesn't segfault on unload. ;-)
(I don't claim to write C or hack kernels, so this presented as-is in
that it "works for me.")
Daniel M. Kurry
--mojUlQ0s9EVzWg2t
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="rtc.diff"
--- rtc.c.bk Thu Aug 15 03:50:21 2002
+++ rtc.c Thu Aug 15 12:08:00 2002
@@ -77,6 +77,8 @@
static struct rtc_softc *rtc_sc=NULL;
+static dev_t rtc_dev=NULL;
+
static d_open_t rtc_open;
static d_close_t rtc_close;
static d_ioctl_t rtc_ioctl;
@@ -115,43 +117,6 @@
/* -=-=-=-=-=-=-=-=-= attach/detach device stuff -=-=-=-=-=-=-=-=-= */
-static struct rtc_softc *
-rtc_attach(dev_t dev)
-{
- struct rtc_softc *sc;
- int unit;
-
-#if __FreeBSD_version >= 500014
- unit = dev2unit(dev);
-#else
- unit = lminor(dev);
-#endif
- DLog(Lenter, "%d %p", unit, dev);
- if (dev->si_drv1) {
- DLog(Lexit, "old %p, %p", dev, dev->si_drv1);
- return dev->si_drv1;
- }
-
- if (rtc_sc!=NULL)
- return NULL;
-
- dev = make_dev(&rtc_cdevsw, minor(dev), UID_ROOT, GID_WHEEL, 0600, DEVICE_NAME);
- if (dev==NULL)
- return (NULL);
-
- MALLOC(sc, struct rtc_softc*, sizeof(*sc), M_DEVBUF, M_WAITOK);
- if (sc==NULL)
- return NULL;
-
- bzero(sc, sizeof(*sc));
- rtc_sc = sc;
- dev->si_drv1 = sc; /* Link together */
- sc->dev = dev;
-
- DLog(Lexit, "new %p,%p", dev, sc);
- return sc;
-}
-
static int
rtc_detach(struct rtc_softc *sc)
{
@@ -163,7 +128,7 @@
if (sc->var.flags.opened) {
return EBUSY;
}
- destroy_dev(sc->dev);
+ destroy_dev(rtc_sc->dev);
FREE(sc, M_DEVBUF);
return error;
}
@@ -177,9 +142,8 @@
rtc_open(dev_t dev, int oflag, int otyp, struct proc *p)
#endif
{
- struct rtc_softc *sc;
+ struct rtc_softc *sc = (struct rtc_softc *) dev->si_drv1;
- sc = rtc_attach(dev);
if (sc==NULL)
return (EAGAIN);
@@ -264,7 +228,21 @@
static int
init_module(void)
{
-int error;
+ int error;
+ struct rtc_softc *sc;
+
+ rtc_dev = make_dev(&rtc_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, DEVICE_NAME);
+ if(rtc_dev==NULL)
+ return (NULL);
+
+ MALLOC(sc, struct rtc_softc*, sizeof(*sc), M_DEVBUF, M_WAITOK);
+ if(sc==NULL)
+ return NULL;
+
+ bzero(sc, sizeof(*sc));
+ rtc_sc = sc;
+ rtc_dev->si_drv1 = rtc_sc; /* Link together */
+ rtc_sc->dev = rtc_dev;
error = cdevsw_add(&rtc_cdevsw);
if (error)
--mojUlQ0s9EVzWg2t--
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020816230831.GD35400>
