Subject: atari softintr(9) patch
To: None <port-atari@NetBSD.org>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: port-m68k
Date: 03/07/2007 01:51:52
(please cc: me on replies since I don't subscribe port-atari)
Here is one for atari.
There are two concerns on implementation:
- Many drivers on this port heavily depend on add_sicallback() function
which uses setsoftcback() in (now obsolete) MD softintr functions.
Some of functions which use this callback should be rewritten to
use MI softintr(9) directly.
- According to <machine/scu.h> and lev1intr() hander in locore.s,
at least _ATARIHW_ machines (ATARITT and HADES?) seem to have
some hardware support which can initiate real hardware interrupt
at ipl 1 for software interrupt. But as per <machine/mtpr.h>,
this feature has not been used at all on setsoft*() calls and
traditional hp300 derived ssir (simulated software interrupt
request) on VAX REI emulation in locore.s is used.
If we'll make this port use this hardware support for softintr(9),
we can't use MI m68k/softintr.c and have to prepare its own
softintr dispatcher.
Anyway, if this patch works, it's enough for intermediate fix,
I believe...
---
Izumi Tsutsui
Index: atari/autoconf.c
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/atari/autoconf.c,v
retrieving revision 1.52
diff -u -r1.52 autoconf.c
--- atari/autoconf.c 11 Dec 2005 12:16:54 -0000 1.52
+++ atari/autoconf.c 6 Mar 2007 16:34:53 -0000
@@ -63,6 +63,9 @@
atari_realconfig = 1;
+ softintr_init();
+ init_sicallback();
+
if (config_rootfound("mainbus", __UNCONST("mainbus")) == NULL)
panic("no mainbus found");
}
Index: atari/intr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/atari/intr.c,v
retrieving revision 1.11
diff -u -r1.11 intr.c
--- atari/intr.c 11 Dec 2005 12:16:54 -0000 1.11
+++ atari/intr.c 6 Mar 2007 16:34:54 -0000
@@ -321,3 +321,26 @@
else
printf("intr_dispatch: stray level %d interrupt\n", vector);
}
+
+static const int ipl2psl_table[] = {
+ [IPL_NONE] = PSL_IPL0,
+ [IPL_SOFT] = PSL_IPL1,
+ [IPL_SOFTCLOCK] = PSL_IPL1,
+ [IPL_SOFTNET] = PSL_IPL1,
+ [IPL_SOFTSERIAL] = PSL_IPL1,
+ [IPL_BIO] = PSL_IPL3,
+ [IPL_NET] = PSL_IPL3,
+ [IPL_TTY] = PSL_IPL4,
+ /* IPL_LPT == IPL_TTY */
+ [IPL_VM] = PSL_IPL4,
+ [IPL_SERIAL] = PSL_IPL5,
+ [IPL_CLOCK] = PSL_IPL6,
+ [IPL_HIGH] = PSL_IPL7,
+};
+
+ipl_cookie_t
+makeiplcookie(ipl_t ipl)
+{
+
+ return (ipl_cookie_t){._psl = ipl2psl_table[ipl] | PSL_S};
+}
Index: atari/locore.s
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/atari/locore.s,v
retrieving revision 1.96
diff -u -r1.96 locore.s
--- atari/locore.s 1 Sep 2006 19:11:56 -0000 1.96
+++ atari/locore.s 6 Mar 2007 16:34:54 -0000
@@ -758,7 +758,7 @@
movl _C_LABEL(stio_addr),%a0 | get KVA of ST-IO area
moveb #0, %a0@(SCU_SOFTINT) | Turn off software interrupt
addql #1,_C_LABEL(intrcnt)+16 | add another software interrupt
- jbsr _C_LABEL(softint) | handle software interrupts
+ jbsr _C_LABEL(softintr_dispatch) | XXX handle software interrupts
moveml %sp@+,%d0-%d1/%a0-%a1
addql #1,_C_LABEL(uvmexp)+UVMEXP_INTRS
jra _ASM_LABEL(rei)
@@ -803,7 +803,6 @@
* point for coprocessor mid-instruction frames (type 9), but we also test
* for bus error frames (type 10 and 11).
*/
- BSS(ssir,1)
ASENTRY_NOPROFILE(rei)
#ifdef DEBUG
tstl _C_LABEL(panicstr) | have we paniced?
Index: atari/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/atari/machdep.c,v
retrieving revision 1.143
diff -u -r1.143 machdep.c
--- atari/machdep.c 4 Mar 2007 05:59:39 -0000 1.143
+++ atari/machdep.c 6 Mar 2007 16:34:54 -0000
@@ -133,7 +133,6 @@
static void bootsync __P((void));
static void call_sicallbacks __P((void));
static void identifycpu __P((void));
-static void netintr __P((void));
void straymfpint __P((int, u_short));
void straytrap __P((int, u_short));
@@ -695,30 +694,6 @@
evec & 0xFFF, pc);
}
-/*
- * Simulated software interrupt handler
- */
-void
-softint()
-{
- if(ssir & SIR_NET) {
- siroff(SIR_NET);
- uvmexp.softs++;
- netintr();
- }
- if(ssir & SIR_CLOCK) {
- siroff(SIR_CLOCK);
- uvmexp.softs++;
- /* XXXX softclock(&frame.f_stackadj); */
- softclock(NULL);
- }
- if (ssir & SIR_CBACK) {
- siroff(SIR_CBACK);
- uvmexp.softs++;
- call_sicallbacks();
- }
-}
-
int *nofault;
int
@@ -755,25 +730,6 @@
}
/*
- * Network interrupt handling
- */
-static void
-netintr()
-{
-#define DONETISR(bit, fn) do { \
- if (netisr & (1 << bit)) { \
- netisr &= ~(1 << bit); \
- fn(); \
- } \
-} while (0)
-
-#include <net/netisr_dispatch.h>
-
-#undef DONETISR
-}
-
-
-/*
* this is a handy package to have asynchronously executed
* function calls executed at very low interrupt priority.
* Example for use is keyboard repeat, where the repeat
@@ -782,18 +738,29 @@
* Note: the installed functions are currently called in a
* LIFO fashion, might want to change this to FIFO
* later.
+ *
+ * XXX: Some of functions which use this callback should be rewritten
+ * XXX: to use MI softintr(9) directly.
*/
struct si_callback {
struct si_callback *next;
void (*function) __P((void *rock1, void *rock2));
void *rock1, *rock2;
};
+static void *si_callback_cookie;
static struct si_callback *si_callbacks;
static struct si_callback *si_free;
#ifdef DIAGNOSTIC
static int ncbd; /* number of callback blocks dynamically allocated */
#endif
+void init_sicallback(void)
+{
+
+ si_callback_cookie = softintr_establish(IPL_SOFT,
+ (void (*)(void *))call_sicallbacks, NULL);
+}
+
void add_sicallback (function, rock1, rock2)
void (*function) __P((void *rock1, void *rock2));
void *rock1, *rock2;
@@ -832,8 +799,17 @@
/*
* and cause a software interrupt (spl1). This interrupt might
* happen immediately, or after returning to a safe enough level.
+ *
+ * XXX:
+ * According to <machine/scu.h> and lev1intr() hander in locore.s,
+ * at least _ATARIHW_ machines (ATARITT and HADES?) seem to have
+ * some hardware support which can initiate real hardware interrupt
+ * at ipl 1 for software interrupt. But as per <machine/mtpr.h>,
+ * this feature was not used at all on setsoft*() calls and
+ * traditional hp300 derived ssir (simulated software interrupt
+ * request) on VAX REI emulation in locore.s is used.
*/
- setsoftcback();
+ softintr_schedule(si_callback_cookie);
}
void rem_sicallback(function)
@@ -880,7 +856,7 @@
rock2 = si->rock2;
s = splhigh ();
if(si_callbacks)
- setsoftcback();
+ softintr_schedule(si_callback_cookie);
si->next = si_free;
si_free = si;
splx(s);
Index: atari/trap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/atari/trap.c,v
retrieving revision 1.87
diff -u -r1.87 trap.c
--- atari/trap.c 4 Mar 2007 05:59:39 -0000 1.87
+++ atari/trap.c 6 Mar 2007 16:34:54 -0000
@@ -107,7 +107,6 @@
#include <machine/trap.h>
#include <machine/cpu.h>
#include <machine/reg.h>
-#include <machine/mtpr.h>
#include <machine/pte.h>
#ifdef DDB
#include <machine/db_machdep.h>
@@ -599,8 +598,9 @@
*/
case T_SSIR:
case T_SSIR|T_USER:
- if(ssir)
- softint();
+
+ softintr_dispatch();
+
/*
* If this was not an AST trap, we are all done.
*/
Index: conf/files.atari
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/conf/files.atari,v
retrieving revision 1.108
diff -u -r1.108 files.atari
--- conf/files.atari 11 Dec 2005 12:16:54 -0000 1.108
+++ conf/files.atari 6 Mar 2007 16:34:54 -0000
@@ -211,6 +211,7 @@
file arch/m68k/m68k/cacheops.c
file arch/m68k/m68k/db_memrw.c ddb
file arch/m68k/m68k/procfs_machdep.c procfs
+file arch/m68k/m68k/softintr.c
file arch/m68k/m68k/sys_machdep.c
file arch/m68k/m68k/vm_machdep.c
Index: include/cpu.h
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/include/cpu.h,v
retrieving revision 1.51
diff -u -r1.51 cpu.h
--- include/cpu.h 4 Mar 2007 05:59:41 -0000 1.51
+++ include/cpu.h 6 Mar 2007 16:34:55 -0000
@@ -164,9 +164,6 @@
extern int astpending; /* need trap before returning to user mode */
extern int want_resched; /* resched() was called */
-/* include support for software interrupts */
-#include <machine/mtpr.h>
-
/*
* The rest of this should probably be moved to ../atari/ataricpu.h,
* although some of it could probably be put into generic 68k headers.
@@ -268,11 +265,11 @@
* Prototypes from machdep.c:
*/
typedef void (*si_farg)(void *, void *); /* XXX */
+void init_sicallback __P((void)); /* XXX */
void add_sicallback __P((si_farg, void *, void *));
void rem_sicallback __P((si_farg));
void dumpsys __P((void));
vaddr_t reserve_dumppages __P((vaddr_t));
-void softint __P((void));
/*
Index: include/intr.h
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/include/intr.h,v
retrieving revision 1.13
diff -u -r1.13 intr.h
--- include/intr.h 16 Feb 2007 02:53:45 -0000 1.13
+++ include/intr.h 6 Mar 2007 16:34:55 -0000
@@ -37,16 +37,22 @@
#define _ATARI_INTR_H_
#define IPL_NONE 0 /* disable no interrupts */
-#define IPL_BIO (PSL_S|PSL_IPL3) /* disable block I/O interrupts */
-#define IPL_NET (PSL_S|PSL_IPL3) /* disable network interrupts */
-#define IPL_TTY (PSL_S|PSL_IPL4) /* disable terminal interrupts */
+#define IPL_SOFTCLOCK 1
+#define IPL_SOFTNET 2
+#define IPL_SOFTSERIAL 3
+#define IPL_SOFT 4
+#define IPL_BIO 5 /* disable block I/O interrupts */
+#define IPL_NET 6 /* disable network interrupts */
+#define IPL_TTY 7 /* disable terminal interrupts */
#define IPL_LPT IPL_TTY
-#define IPL_VM (PSL_S|PSL_IPL4)
-#define IPL_CLOCK (PSL_S|PSL_IPL6) /* disable clock interrupts */
+#define IPL_VM 8
+#define IPL_SERIAL 9
+#define IPL_CLOCK 10 /* disable clock interrupts */
#define IPL_STATCLOCK IPL_CLOCK
-#define IPL_HIGH (PSL_S|PSL_IPL7) /* disable all interrupts */
+#define IPL_HIGH 11 /* disable all interrupts */
#define IPL_SCHED IPL_HIGH
#define IPL_LOCK IPL_HIGH
+#define NIPL 12
#define IST_UNUSABLE -1 /* interrupt cannot be used */
#define IST_NONE 0 /* none (dummy) */
@@ -63,13 +69,15 @@
#define splnone() spl0()
-#define splsoftclock() splraise1()
-#define splsoftnet() splraise1()
-
-#define splbio() _splraise(PSL_S|PSL_IPL3)
-#define splnet() _splraise(PSL_S|PSL_IPL3)
-#define spltty() _splraise(PSL_S|PSL_IPL4)
-#define splvm() _splraise(PSL_S|PSL_IPL4)
+#define splsoft() splraise1()
+#define splsoftclock() splsoft()
+#define splsoftnet() splsoft()
+#define splsoftserial() splsoft()
+
+#define splbio() splraise3()
+#define splnet() splraise3()
+#define spltty() splraise4()
+#define splvm() splraise4()
#define spllpt() spltty()
@@ -86,22 +94,20 @@
typedef int ipl_t;
typedef struct {
- int _ipl;
+ int _psl;
} ipl_cookie_t;
-static inline ipl_cookie_t
-makeiplcookie(ipl_t ipl)
-{
-
- return (ipl_cookie_t){._ipl = ipl};
-}
+ipl_cookie_t makeiplcookie(ipl_t);
static inline int
splraiseipl(ipl_cookie_t icookie)
{
- return _splraise(icookie._ipl);
+ return _splraise(icookie._psl);
}
+
+#include <m68k/softintr.h>
+
#endif /* _KERNEL */
#endif /* _ATARI_INTR_H_ */
Index: include/types.h
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/include/types.h,v
retrieving revision 1.8
diff -u -r1.8 types.h
--- include/types.h 28 Feb 2002 03:17:32 -0000 1.8
+++ include/types.h 6 Mar 2007 16:34:55 -0000
@@ -4,5 +4,6 @@
#define _MACHINE_TYPES_H_
#include <m68k/types.h>
+#define __HAVE_GENERIC_SOFT_INTERRUPTS
#endif