Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/usermode add sigio_intr_establish so more than one ...



details:   https://anonhg.NetBSD.org/src/rev/d97b24a81cc6
branches:  trunk
changeset: 772245:d97b24a81cc6
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon Dec 26 12:29:38 2011 +0000

description:
add sigio_intr_establish so more than one driver can register a SIGIO handler

diffstat:

 sys/arch/usermode/dev/ttycons.c   |  20 +++++++--------
 sys/arch/usermode/include/intr.h  |   5 +++-
 sys/arch/usermode/usermode/intr.c |  50 +++++++++++++++++++++++++++++++++++++-
 sys/arch/usermode/usermode/trap.c |   7 +++-
 4 files changed, 66 insertions(+), 16 deletions(-)

diffs (188 lines):

diff -r 1b92a93b00ef -r d97b24a81cc6 sys/arch/usermode/dev/ttycons.c
--- a/sys/arch/usermode/dev/ttycons.c   Mon Dec 26 00:20:43 2011 +0000
+++ b/sys/arch/usermode/dev/ttycons.c   Mon Dec 26 12:29:38 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ttycons.c,v 1.15 2011/12/21 11:53:07 jmcneill Exp $ */
+/* $NetBSD: ttycons.c,v 1.16 2011/12/26 12:29:38 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ttycons.c,v 1.15 2011/12/21 11:53:07 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ttycons.c,v 1.16 2011/12/26 12:29:38 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -99,7 +99,7 @@
 static void    ttycons_start(struct tty *);
 static int     ttycons_param(struct tty *, struct termios *);
 
-static void    ttycons_intr(int);
+static int     ttycons_intr(void *);
 static void    ttycons_softintr(void *);
 
 static void    ttycons_ctrlc(int);
@@ -146,7 +146,7 @@
        if (sc->sc_ctrlc_sih == NULL)
                panic("couldn't establish ttycons ctrlc handler\n");
 
-       thunk_signal(SIGIO, ttycons_intr);
+       sigio_intr_establish(ttycons_intr, sc);
        thunk_signal(SIGINT, ttycons_ctrlc);
        if (thunk_set_stdin_sigio(true) != 0)
                panic("couldn't enable stdin async mode");
@@ -348,18 +348,16 @@
        return 0;
 }
 
-static void
-ttycons_intr(int sig)
+static int
+ttycons_intr(void *priv)
 {
-       struct ttycons_softc *sc;
+       struct ttycons_softc *sc = priv;
 
        curcpu()->ci_idepth++;
-       sc = device_lookup_private(&ttycons_cd, minor(cn_tab->cn_dev));
-       if (sc) {
-               spl_intr(IPL_SERIAL, softint_schedule, sc->sc_rd_sih);
-       }
+       spl_intr(IPL_SERIAL, softint_schedule, sc->sc_rd_sih);
        curcpu()->ci_idepth--;
 
+       return 0;
 }
 
 static void
diff -r 1b92a93b00ef -r d97b24a81cc6 sys/arch/usermode/include/intr.h
--- a/sys/arch/usermode/include/intr.h  Mon Dec 26 00:20:43 2011 +0000
+++ b/sys/arch/usermode/include/intr.h  Mon Dec 26 12:29:38 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: intr.h,v 1.4 2011/09/12 12:24:34 reinoud Exp $ */
+/* $NetBSD: intr.h,v 1.5 2011/12/26 12:29:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -31,6 +31,9 @@
 
 #include <machine/intrdefs.h>
 
+void   sigio_intr_init(void);
+void * sigio_intr_establish(int (*)(void *), void *);
+
 void   splinit(void);
 int    splraise(int);
 void   spllower(int);
diff -r 1b92a93b00ef -r d97b24a81cc6 sys/arch/usermode/usermode/intr.c
--- a/sys/arch/usermode/usermode/intr.c Mon Dec 26 00:20:43 2011 +0000
+++ b/sys/arch/usermode/usermode/intr.c Mon Dec 26 12:29:38 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: intr.c,v 1.9 2011/12/13 12:27:06 reinoud Exp $ */
+/* $NetBSD: intr.c,v 1.10 2011/12/26 12:29:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,13 +27,22 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.9 2011/12/13 12:27:06 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.10 2011/12/26 12:29:39 jmcneill Exp $");
 
 #include <sys/types.h>
 
 #include <machine/intr.h>
 #include <machine/thunk.h>
 
+struct intr_handler {
+       int (*func)(void *);
+       void *arg;
+};
+
+#define SIGIO_MAX_HANDLERS     2
+
+static struct intr_handler sigio_intr_handler[SIGIO_MAX_HANDLERS];
+
 //#define INTR_USE_SIGPROCMASK
 
 #define MAX_QUEUED_EVENTS 128
@@ -134,3 +143,40 @@
        }
 #endif
 }
+
+static void
+sigio_signal_handler(int sig)
+{
+       struct intr_handler *sih;
+       unsigned int n;
+
+       for (n = 0; n < SIGIO_MAX_HANDLERS; n++) {
+               sih = &sigio_intr_handler[n];
+               if (sih->func)
+                       sih->func(sih->arg);
+       }
+}
+
+void
+sigio_intr_init(void)
+{
+       thunk_signal(SIGIO, sigio_signal_handler);
+}
+
+void *
+sigio_intr_establish(int (*func)(void *), void *arg)
+{
+       struct intr_handler *sih;
+       unsigned int n;
+
+       for (n = 0; n < SIGIO_MAX_HANDLERS; n++) {
+               sih = &sigio_intr_handler[n];
+               if (sih->func == NULL) {
+                       sih->func = func;
+                       sih->arg = arg;
+                       return sih;
+               }
+       }
+
+       panic("increase SIGIO_MAX_HANDLERS");
+}
diff -r 1b92a93b00ef -r d97b24a81cc6 sys/arch/usermode/usermode/trap.c
--- a/sys/arch/usermode/usermode/trap.c Mon Dec 26 00:20:43 2011 +0000
+++ b/sys/arch/usermode/usermode/trap.c Mon Dec 26 12:29:38 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.46 2011/12/25 21:10:00 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.47 2011/12/26 12:29:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <reinoud%netbsd.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.46 2011/12/25 21:10:00 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.47 2011/12/26 12:29:39 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -42,6 +42,7 @@
 #include <machine/pcb.h>
 #include <machine/pmap.h>
 #include <machine/machdep.h>
+#include <machine/intr.h>
 #include <machine/thunk.h>
 
 
@@ -94,6 +95,8 @@
 //     thunk_sigaddset(&sa.sa_mask, SIGALRM);
        if (thunk_sigaction(SIGILL, &sa, NULL) == -1)
                panic("couldn't register SIGILL handler : %d", thunk_geterrno());
+
+       sigio_intr_init();
 }
 
 



Home | Main Index | Thread Index | Old Index