Module Name: src
Committed By: jmcneill
Date: Mon Dec 26 12:29:39 UTC 2011
Modified Files:
src/sys/arch/usermode/dev: ttycons.c
src/sys/arch/usermode/include: intr.h
src/sys/arch/usermode/usermode: intr.c trap.c
Log Message:
add sigio_intr_establish so more than one driver can register a SIGIO handler
To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/usermode/dev/ttycons.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/usermode/include/intr.h
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/usermode/usermode/intr.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/usermode/usermode/trap.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/usermode/dev/ttycons.c
diff -u src/sys/arch/usermode/dev/ttycons.c:1.15 src/sys/arch/usermode/dev/ttycons.c:1.16
--- src/sys/arch/usermode/dev/ttycons.c:1.15 Wed Dec 21 11:53:07 2011
+++ src/sys/arch/usermode/dev/ttycons.c Mon Dec 26 12:29:38 2011
@@ -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 <[email protected]>
@@ -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 @@ const struct cdevsw ttycons_cdevsw = {
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 @@ ttycons_attach(device_t parent, device_t
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 @@ ttycons_param(struct tty *t, struct term
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
Index: src/sys/arch/usermode/include/intr.h
diff -u src/sys/arch/usermode/include/intr.h:1.4 src/sys/arch/usermode/include/intr.h:1.5
--- src/sys/arch/usermode/include/intr.h:1.4 Mon Sep 12 12:24:34 2011
+++ src/sys/arch/usermode/include/intr.h Mon Dec 26 12:29:39 2011
@@ -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 <[email protected]>
@@ -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);
Index: src/sys/arch/usermode/usermode/intr.c
diff -u src/sys/arch/usermode/usermode/intr.c:1.9 src/sys/arch/usermode/usermode/intr.c:1.10
--- src/sys/arch/usermode/usermode/intr.c:1.9 Tue Dec 13 12:27:06 2011
+++ src/sys/arch/usermode/usermode/intr.c Mon Dec 26 12:29:39 2011
@@ -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 <[email protected]>
@@ -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 @@ spllower(int x)
}
#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");
+}
Index: src/sys/arch/usermode/usermode/trap.c
diff -u src/sys/arch/usermode/usermode/trap.c:1.46 src/sys/arch/usermode/usermode/trap.c:1.47
--- src/sys/arch/usermode/usermode/trap.c:1.46 Sun Dec 25 21:10:00 2011
+++ src/sys/arch/usermode/usermode/trap.c Mon Dec 26 12:29:39 2011
@@ -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 <[email protected]>
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.4
#include <machine/pcb.h>
#include <machine/pmap.h>
#include <machine/machdep.h>
+#include <machine/intr.h>
#include <machine/thunk.h>
@@ -94,6 +95,8 @@ setup_signal_handlers(void)
// 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();
}