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
> [EMAIL PROTECTED]      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

--- 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) 

Reply via email to