Module Name: src Committed By: reinoud Date: Mon Sep 12 12:24:34 UTC 2011
Modified Files: src/sys/arch/usermode/include: intr.h src/sys/arch/usermode/usermode: intr.c machdep.c Log Message: Implement spl level based priority interrupt controller in software To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/arch/usermode/include/intr.h cvs rdiff -u -r1.4 -r1.5 src/sys/arch/usermode/usermode/intr.c cvs rdiff -u -r1.29 -r1.30 src/sys/arch/usermode/usermode/machdep.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/include/intr.h diff -u src/sys/arch/usermode/include/intr.h:1.3 src/sys/arch/usermode/include/intr.h:1.4 --- src/sys/arch/usermode/include/intr.h:1.3 Sun Sep 4 21:08:18 2011 +++ src/sys/arch/usermode/include/intr.h Mon Sep 12 12:24:34 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: intr.h,v 1.3 2011/09/04 21:08:18 jmcneill Exp $ */ +/* $NetBSD: intr.h,v 1.4 2011/09/12 12:24:34 reinoud Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca> @@ -31,8 +31,10 @@ #include <machine/intrdefs.h> +void splinit(void); int splraise(int); void spllower(int); +void spl_intr(int x, void (*func)(void *), void *arg); #define spl0() spllower(IPL_NONE) #define splx(x) spllower(x) Index: src/sys/arch/usermode/usermode/intr.c diff -u src/sys/arch/usermode/usermode/intr.c:1.4 src/sys/arch/usermode/usermode/intr.c:1.5 --- src/sys/arch/usermode/usermode/intr.c:1.4 Thu Sep 8 11:13:03 2011 +++ src/sys/arch/usermode/usermode/intr.c Mon Sep 12 12:24:34 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: intr.c,v 1.4 2011/09/08 11:13:03 jmcneill Exp $ */ +/* $NetBSD: intr.c,v 1.5 2011/09/12 12:24:34 reinoud Exp $ */ /*- * Copyright (c) 2011 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,14 +27,16 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.4 2011/09/08 11:13:03 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.5 2011/09/12 12:24:34 reinoud Exp $"); #include <sys/types.h> #include <machine/intr.h> #include <machine/thunk.h> -/* #define INTR_USE_SIGPROCMASK */ +//#define INTR_USE_SIGPROCMASK + +#define MAX_QUEUED_EVENTS 64 static int usermode_x = IPL_NONE; @@ -42,6 +44,46 @@ static bool block_sigalrm = false; #endif + +struct spl_intr_event { + void (*func)(void *); + void *arg; +}; + +struct spl_intr_event spl_intrs[IPL_HIGH+1][MAX_QUEUED_EVENTS]; +int spl_intr_wr[IPL_HIGH+1]; +int spl_intr_rd[IPL_HIGH+1]; + +void +splinit(void) +{ + int i; + for (i = 0; i <= IPL_HIGH; i++) { + spl_intr_rd[i] = 1; + spl_intr_wr[i] = 1; + } +} + +void +spl_intr(int x, void (*func)(void *), void *arg) +{ + struct spl_intr_event *spli; + + if (x >= usermode_x) { + func(arg); + return; + } + + //printf("\nX : %d\n", x); + spli = &spl_intrs[x][spl_intr_wr[x]]; + spli->func = func; + spli->arg = arg; + + spl_intr_wr[x] = (spl_intr_wr[x] + 1) % MAX_QUEUED_EVENTS; + if (spl_intr_wr[x] == spl_intr_rd[x]) + panic("%s: spl list %d full!\n", __func__, x); +} + int splraise(int x) { @@ -64,8 +106,24 @@ void spllower(int x) { - if (usermode_x > x) + struct spl_intr_event *spli; + int y; + + /* `eat' interrupts that came by until we got back to x */ + if (usermode_x > x) { + for (y = usermode_x; y >= x; y--) { + while (spl_intr_rd[y] != spl_intr_wr[y]) { + // printf("spl y %d firing\n", y); + spli = &spl_intrs[y][spl_intr_rd[y]]; + if (!spli->func) + panic("%s: spli->func is NULL for ipl %d, rd %d, wr %d\n", + __func__, y, spl_intr_rd[y], spl_intr_wr[y]); + spli->func(spli->arg); + spl_intr_rd[y] = (spl_intr_rd[y] + 1) % MAX_QUEUED_EVENTS; + } + } usermode_x = x; + } #ifdef INTR_USE_SIGPROCMASK if (x < IPL_SCHED && block_sigalrm) { Index: src/sys/arch/usermode/usermode/machdep.c diff -u src/sys/arch/usermode/usermode/machdep.c:1.29 src/sys/arch/usermode/usermode/machdep.c:1.30 --- src/sys/arch/usermode/usermode/machdep.c:1.29 Fri Sep 9 20:06:04 2011 +++ src/sys/arch/usermode/usermode/machdep.c Mon Sep 12 12:24:34 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.29 2011/09/09 20:06:04 reinoud Exp $ */ +/* $NetBSD: machdep.c,v 1.30 2011/09/12 12:24:34 reinoud Exp $ */ /*- * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org> @@ -32,7 +32,7 @@ #include "opt_urkelvisor.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.29 2011/09/09 20:06:04 reinoud Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.30 2011/09/12 12:24:34 reinoud Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -113,6 +113,7 @@ urkelvisor_init(); #endif + splinit(); splraise(IPL_HIGH); kernmain();