Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/wscons Make it possible to detach wsmouse and wskbd.



details:   https://anonhg.NetBSD.org/src/rev/cf0a1642bf6c
branches:  trunk
changeset: 474161:cf0a1642bf6c
user:      augustss <augustss%NetBSD.org@localhost>
date:      Wed Jun 30 06:21:21 1999 +0000

description:
Make it possible to detach wsmouse and wskbd.
XXX wskbd probably needs some more work.

diffstat:

 sys/dev/wscons/wskbd.c   |  118 +++++++++++++++++++++++++++++++++++++---
 sys/dev/wscons/wsmouse.c |  136 +++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 230 insertions(+), 24 deletions(-)

diffs (truncated from 475 to 300 lines):

diff -r 3f1f95cd50d8 -r cf0a1642bf6c sys/dev/wscons/wskbd.c
--- a/sys/dev/wscons/wskbd.c    Wed Jun 30 03:52:04 1999 +0000
+++ b/sys/dev/wscons/wskbd.c    Wed Jun 30 06:21:21 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wskbd.c,v 1.23 1999/05/16 19:21:31 thorpej Exp $ */
+/* $NetBSD: wskbd.c,v 1.24 1999/06/30 06:21:21 augustss Exp $ */
 
 /*
  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
@@ -36,7 +36,7 @@
 static const char _copyright[] __attribute__ ((unused)) =
     "Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.";
 static const char _rcsid[] __attribute__ ((unused)) =
-    "$NetBSD: wskbd.c,v 1.23 1999/05/16 19:21:31 thorpej Exp $";
+    "$NetBSD: wskbd.c,v 1.24 1999/06/30 06:21:21 augustss Exp $";
 
 /*
  * Copyright (c) 1992, 1993
@@ -102,6 +102,7 @@
 #include <sys/signalvar.h>
 #include <sys/errno.h>
 #include <sys/fcntl.h>
+#include <sys/vnode.h>
 
 #include <dev/wscons/wsconsio.h>
 #include <dev/wscons/wskbdvar.h>
@@ -156,6 +157,10 @@
        int     sc_maplen;              /* number of entries in sc_map */
        struct wscons_keymap *sc_map;   /* current translation map */
        kbd_t sc_layout; /* current layout */
+
+       int             sc_refcnt;
+       u_char          sc_dying;       /* device is being detached */
+
 };
 
 #define MOD_SHIFT_L            (1 << 0)
@@ -183,6 +188,9 @@
 
 int    wskbd_match __P((struct device *, struct cfdata *, void *));
 void   wskbd_attach __P((struct device *, struct device *, void *));
+int    wskbd_detach __P((struct device *, int));
+int    wskbd_activate __P((struct device *, enum devact));
+
 static inline void update_leds __P((struct wskbd_internal *));
 static inline void update_modifier __P((struct wskbd_internal *, u_int, int, int));
 static int internal_command __P((struct wskbd_softc *, u_int *, keysym_t));
@@ -192,6 +200,9 @@
 static void wskbd_holdscreen __P((struct wskbd_softc *, int));
 #endif
 
+int    wskbd_do_ioctl __P((struct wskbd_softc *, u_long, caddr_t, 
+                           int, struct proc *));
+
 struct cfattach wskbd_ca = {
        sizeof (struct wskbd_softc), wskbd_match, wskbd_attach,
 };
@@ -384,6 +395,62 @@
 }
 #endif
 
+int
+wskbd_activate(self, act)
+       struct device *self;
+       enum devact act;
+{
+       /* XXX should we do something more? */
+       return (0);
+}
+
+/*
+ * Detach a keyboard.  To keep track of users of the softc we keep
+ * a reference count that's incremented while inside, e.g., read.
+ * If the mouse is active and the reference count is > 0 (0 is the
+ * normal state) we post an event and then wait for the process
+ * that had the reference to wake us up again.  Then we blow away the
+ * vnode and return (which will deallocate the softc).
+ * XXX what should we do if we are connected to a display?
+ */
+int
+wskbd_detach(self, flags)
+       struct device  *self;
+       int flags;
+{
+       struct wskbd_softc *sc = (struct wskbd_softc *)self;
+       struct wseventvar *evar;
+       int maj, mn;
+       int s;
+
+       evar = &sc->sc_events;
+       if (evar->io) {
+               s = spltty();
+               if (--sc->sc_refcnt >= 0) {
+                       /* Wake everyone by generating a dummy event. */
+                       if (++evar->put >= WSEVENT_QSIZE)
+                               evar->put = 0;
+                       WSEVENT_WAKEUP(evar);
+                       /* Wait for processes to go away. */
+                       if (tsleep(sc, PZERO, "wskdet", hz * 60))
+                               printf("wskbd_detach: %s didn't detach\n",
+                                      sc->sc_dv.dv_xname);
+               }
+               splx(s);
+       }
+
+       /* locate the major number */
+       for (maj = 0; maj < nchrdev; maj++)
+               if (cdevsw[maj].d_open == wskbdopen)
+                       break;
+
+       /* Nuke the vnodes for any open instances. */
+       mn = self->dv_unit;
+       vdevgone(maj, mn, mn, VCHR);
+
+       return (0);
+}
+
 void
 wskbd_input(dev, type, value)
        struct device *dev;
@@ -392,6 +459,7 @@
 {
        struct wskbd_softc *sc = (struct wskbd_softc *)dev; 
        struct wscons_event *ev;
+       struct wseventvar *evar;
        struct timeval xxxtime;
 #if NWSDISPLAY > 0
        keysym_t ks;
@@ -405,7 +473,7 @@
        }
 
        /*
-        * If /dev/kbd is not connected in event mode translate and
+        * If /dev/wskbd is not connected in event mode translate and
         * send upstream.
         */
        if (sc->sc_translating) {
@@ -434,10 +502,12 @@
        if (!sc->sc_ready)
                return;
 
-       put = sc->sc_events.put;
-       ev = &sc->sc_events.q[put];
+       evar = &sc->sc_events;
+
+       put = evar->put;
+       ev = &evar->q[put];
        put = (put + 1) % WSEVENT_QSIZE;
-       if (put == sc->sc_events.get) {
+       if (put == evar->get) {
                log(LOG_WARNING, "%s: event queue overflow\n",
                    sc->sc_dv.dv_xname);
                return;
@@ -446,8 +516,8 @@
        ev->value = value;
        microtime(&xxxtime);
        TIMEVAL_TO_TIMESPEC(&xxxtime, &ev->time);
-       sc->sc_events.put = put;
-       WSEVENT_WAKEUP(&sc->sc_events);
+       evar->put = put;
+       WSEVENT_WAKEUP(evar);
 }
 
 #ifdef WSDISPLAY_COMPAT_RAWKBD
@@ -525,6 +595,9 @@
            (sc = wskbd_cd.cd_devs[unit]) == NULL)
                return (ENXIO);
 
+       if (sc->sc_dying)
+               return (EIO);
+
        if (sc->sc_events.io)                   /* and that it's not in use */
                return (EBUSY);
 
@@ -563,8 +636,18 @@
        int flags;
 {
        struct wskbd_softc *sc = wskbd_cd.cd_devs[minor(dev)];
+       int error;
 
-       return (wsevent_read(&sc->sc_events, uio, flags));
+       if (sc->sc_dying)
+               return (EIO);
+
+       sc->sc_refcnt++;
+       error = wsevent_read(&sc->sc_events, uio, flags);
+       if (--sc->sc_refcnt < 0) {
+               wakeup(sc);
+               error = EIO;
+       }
+       return (error);
 }
 
 int
@@ -578,6 +661,23 @@
        struct wskbd_softc *sc = wskbd_cd.cd_devs[minor(dev)];
        int error;
 
+       sc->sc_refcnt++;
+       error = wskbd_do_ioctl(sc, cmd, data, flag, p);
+       if (--sc->sc_refcnt < 0)
+               wakeup(sc);
+       return (error);
+}
+
+int
+wskbd_do_ioctl(sc, cmd, data, flag, p)
+       struct wskbd_softc *sc;
+       u_long cmd;
+       caddr_t data;
+       int flag;
+       struct proc *p;
+{
+       int error;
+
        /*      
         * Try the generic ioctls that the wskbd interface supports.
         */
diff -r 3f1f95cd50d8 -r cf0a1642bf6c sys/dev/wscons/wsmouse.c
--- a/sys/dev/wscons/wsmouse.c  Wed Jun 30 03:52:04 1999 +0000
+++ b/sys/dev/wscons/wsmouse.c  Wed Jun 30 06:21:21 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wsmouse.c,v 1.6 1999/01/10 18:22:14 augustss Exp $ */
+/* $NetBSD: wsmouse.c,v 1.7 1999/06/30 06:21:21 augustss Exp $ */
 
 /*
  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
@@ -33,7 +33,7 @@
 static const char _copyright[] __attribute__ ((unused)) =
     "Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.";
 static const char _rcsid[] __attribute__ ((unused)) =
-    "$NetBSD: wsmouse.c,v 1.6 1999/01/10 18:22:14 augustss Exp $";
+    "$NetBSD: wsmouse.c,v 1.7 1999/06/30 06:21:21 augustss Exp $";
 
 /*
  * Copyright (c) 1992, 1993
@@ -94,6 +94,7 @@
 #include <sys/tty.h>
 #include <sys/signalvar.h>
 #include <sys/device.h>
+#include <sys/vnode.h>
 
 #include <dev/wscons/wsconsio.h>
 #include <dev/wscons/wsmousevar.h>
@@ -115,13 +116,23 @@
        int             sc_dx;          /* delta-x */
        int             sc_dy;          /* delta-y */
        int             sc_dz;          /* delta-z */
+
+       int             sc_refcnt;
+       u_char          sc_dying;       /* device is being detached */
+
 };
 
 int    wsmouse_match __P((struct device *, struct cfdata *, void *));
 void   wsmouse_attach __P((struct device *, struct device *, void *));
+int    wsmouse_detach __P((struct device *, int));
+int    wsmouse_activate __P((struct device *, enum devact));
+
+int    wsmouse_do_ioctl __P((struct wsmouse_softc *, u_long, caddr_t, 
+                             int, struct proc *));
 
 struct cfattach wsmouse_ca = {
        sizeof (struct wsmouse_softc), wsmouse_match, wsmouse_attach,
+       wsmouse_detach, wsmouse_activate
 };
 
 #if NWSMOUSE > 0
@@ -150,7 +161,6 @@
        struct cfdata *match;
        void *aux;
 {
-
        return (1);
 }
 
@@ -162,11 +172,68 @@
         struct wsmouse_softc *sc = (struct wsmouse_softc *)self;
        struct wsmousedev_attach_args *ap = aux;
 
-       printf("\n");
-
        sc->sc_accessops = ap->accessops;
        sc->sc_accesscookie = ap->accesscookie;
        sc->sc_ready = 0;                               /* sanity */
+
+       printf("\n");
+}
+
+int
+wsmouse_activate(self, act)
+       struct device *self;
+       enum devact act;
+{
+       /* XXX should we do something more? */
+       return (0);
+}
+
+/*
+ * Detach a mouse.  To keep track of users of the softc we keep



Home | Main Index | Thread Index | Old Index