Subject: port-mac68k/6112: Adding external cache support of DayStar PowerCache accelerator
To: None <gnats-bugs@gnats.netbsd.org>
From: None <kei_sun@ba2.so-net.ne.jp>
List: netbsd-bugs
Date: 09/07/1998 00:36:11
>Number:         6112
>Category:       port-mac68k
>Synopsis:       Adding external cache support of DayStar PowerCache accelerator
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Sep  6 08:35:00 1998
>Last-Modified:
>Originator:     SUNAGAWA Keiki <kei_sun@ba2.so-net.ne.jp>
>Organization:
	None
>Release:        as of 1998-07-26
>Environment:
System: NetBSD p84ce0b 1.3F NetBSD 1.3F (MINT) #111: Sun Sep 6 12:52:28 JST 1998 kei@localhost:/var/src/sys/arch/mac68k/compile/MINT mac68k
Macintosh IIci, DayStar PowerCache 68030/68882 50MHz, 32KB ext. writeback cache

>Description:
	This patch adds ext. cache support of DayStar PowerCache accelerator.
>How-To-Repeat:
	Turn external cache on within MacOS, boot NetBSD and see it hangs.
>Fix:
	This patch adds external writeback cache support of DayStar PowerCache
	accelerator.  I've been using this for months without any trouble.

* DayStar PowerCache support.  Original work was done by Kevin Radke, merged
  into 1.2(E?) source by David Condon.  Applying them to 1.3F and adding
  support to handle shutdown properly by me.

Index: locore.s
===================================================================
RCS file: /var/cvsroot/src/sys/arch/mac68k/mac68k/locore.s,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -u -r1.1.1.1 -r1.3
--- locore.s	1998/07/26 17:28:48	1.1.1.1
+++ locore.s	1998/09/06 15:00:34	1.3
@@ -118,6 +118,9 @@
 GLOBAL(bletch)
 	.long	0
 
+	.globl	_disable_daystar	| in pmap.c /* kmr */
+
+
 BSS(esym,4)
 
 ASENTRY_NOPROFILE(start)
@@ -150,6 +153,7 @@
 	movc	cacr,d0			| read it back
 	tstl	d0			| zero?
 	jeq	Lnot68030		| yes, we have 68020/68040
+	jbsr    _disable_daystar | Disable daystar external cache /* kmr */
 
 	movl	#CACHE_OFF,d0		| disable and clear both caches
 	movc	d0,cacr
@@ -314,10 +318,13 @@
 
 /* flush TLB and turn on caches */
 	jbsr	_C_LABEL(TBIA)		| invalidate TLB
+        .globl  _flush_daystar /* kmr */
 	cmpl	#MMU_68040,_C_LABEL(mmutype) | 68040?
 	jeq	Lnocache0		| yes, cache already on
 	movl	#CACHE_ON,d0
 	movc	d0,cacr			| clear cache(s)
+        jbsr    _flush_daystar          | flush daystar external cache /* kmr */
+
 #ifdef __notyet__
 	tstl	_C_LABEL(ectype)
 	jeq	Lnocache0
@@ -1319,12 +1326,15 @@
 	movl	#DC_CLEAR,d0
 	movc	d0,cacr			| invalidate on-chip d-cache
 Ltbia851:
+        jbsr    _flush_daystar		| flush daystar external cache /* kmr */
 	rts
 
 /*
  * Invalidate any TLB entry for given VA (TB Invalidate Single)
  */
 ENTRY(TBIS)
+        .globl  _flush_daystar /* kmr */
+
 #ifdef DEBUG
 	tstl	_ASM_LABEL(fulltflush)	| being conservative?
 	jne	_C_LABEL(_TBIA)		| yes, flush entire TLB
@@ -1354,12 +1364,15 @@
 	pflush	#0,#0,a0@		| flush address from both sides
 	movl	#DC_CLEAR,d0
 	movc	d0,cacr			| invalidate on-chip data cache
+        jbsr    _flush_daystar		| flush daystar external cache /* kmr */
 	rts
 
 /*
  * Invalidate supervisor side of TLB
  */
 ENTRY(TBIAS)
+        .globl  _flush_daystar /* kmr */
+
 #ifdef DEBUG
 	tstl	_ASM_LABEL(fulltflush)	| being conservative?
 	jne	_C_LABEL(_TBIA)		| yes, flush everything
@@ -1381,12 +1394,14 @@
 	pflush	#4,#4			| flush supervisor TLB entries
 	movl	#DC_CLEAR,d0
 	movc	d0,cacr			| invalidate on-chip d-cache
+        jbsr    _flush_daystar		| flush daystar external cache /* kmr */
 	rts
 
 /*
  * Invalidate user side of TLB
  */
 ENTRY(TBIAU)
+        .globl  _flush_daystar /* kmr */
 #ifdef DEBUG
 	tstl	_ASM_LABEL(fulltflush)	| being conservative?
 	jne	_C_LABEL(_TBIA)		| yes, flush everything
@@ -1407,6 +1422,7 @@
 	pflush	#0,#4			| flush user TLB entries
 	movl	#DC_CLEAR,d0
 	movc	d0,cacr			| invalidate on-chip d-cache
+        jbsr    _flush_daystar		| flush daystar external cache /* kmr */
 	rts
 
 /*
@@ -1493,6 +1509,7 @@
 #endif /* M68040 */
 
 ENTRY(PCIA)
+        .globl  _flush_daystar /* kmr */
 #if defined(M68040)
 ENTRY(DCFA)
 	cmpl	#MMU_68040,_C_LABEL(mmutype) | 68040?
@@ -1503,6 +1520,7 @@
 #endif
 	movl	#DC_CLEAR,d0
 	movc	d0,cacr			| invalidate on-chip d-cache
+        jbsr    _flush_daystar		| flush daystar external cache /* kmr */
 	rts
 
 ENTRY(ecacheon)
Index: machdep.c
===================================================================
RCS file: /var/cvsroot/src/sys/arch/mac68k/mac68k/machdep.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -u -r1.1.1.1 -r1.2
--- machdep.c	1998/07/26 17:28:48	1.1.1.1
+++ machdep.c	1998/09/04 00:46:08	1.2
@@ -268,6 +268,10 @@
  */
 cpu_kcore_hdr_t cpu_kcore_hdr;
 
+#ifdef POWERCACHE_SUPPORT
+extern inline void disable_daystar __P((void));	/* in pmap.c */
+#endif
+
 /*
  * Early initialization, before main() is called.
  */
@@ -725,6 +729,9 @@
 #if __GNUC__	/* XXX work around lame compiler problem (gcc 2.7.2) */
 	(void)&howto;
 #endif
+#ifdef POWERCACHE_SUPPORT
+	disable_daystar();	/* disable daystar external cache */
+#endif /* POWERCACHE_SUPPORT */
 	/* take a snap shot before clobbering any registers */
 	if (curproc && curproc->p_addr)
 		savectx(&curproc->p_addr->u_pcb);
Index: pmap.c
===================================================================
RCS file: /var/cvsroot/src/sys/arch/mac68k/mac68k/pmap.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -u -r1.1.1.1 -r1.2
--- pmap.c	1998/07/26 17:28:49	1.1.1.1
+++ pmap.c	1998/09/04 00:46:10	1.2
@@ -282,6 +282,9 @@
 int		page_cnt;	/* number of pages managed by VM system */
 
 boolean_t	pmap_initialized = FALSE;	/* Has pmap_init completed? */
+#ifdef POWERCACHE_SUPPORT
+boolean_t	daystar_initialized = FALSE; /* Has map_daystar completed? */
+#endif /* POWERCACHE_SUPPORT */
 struct pv_entry	*pv_table;
 char		*pmap_attributes;	/* reference and modify bits */
 TAILQ_HEAD(pv_page_list, pv_page) pv_page_freelist;
@@ -328,6 +331,12 @@
 void	pmap_changebit	__P((vm_offset_t, int, boolean_t));
 void	pmap_enter_ptpage	__P((pmap_t, vm_offset_t));
 void	pmap_collect1	__P((pmap_t, vm_offset_t, vm_offset_t));
+#ifdef POWERCACHE_SUPPORT
+inline void	flush_daystar	__P((void));
+inline void	disable_daystar	__P((void));
+inline void	enable_daystar	__P((void));
+inline void	map_daystar	__P((void));
+#endif /* POWERCACHE_SUPPORT */
 
 #ifdef DEBUG
 void	pmap_pvdump          __P((vm_offset_t));
@@ -541,6 +550,13 @@
 		       atop(s), addr, addr + s);
 #endif
 
+#ifdef POWERCACHE_SUPPORT
+        /*
+         * Map physical memory addresses used by daystar accelerator
+         */
+        map_daystar();
+#endif /* POWERCACHE_SUPPORT */
+
 	/*
 	 * Allocate the segment table map
 	 */
@@ -2630,3 +2646,83 @@
 
 	return -1;
 }
+
+#ifdef POWERCACHE_SUPPORT
+/*
+ * DayStar PowerCache support routines
+ *
+ *   This routines are originally written by Kevin Radke for NetBSD-XXX and
+ *   modified to fit NetBSD-XXX by David Condon <david@apk.net>.
+ */
+
+/*
+ * flush_daystar()
+ *
+ *   Flush external cache of DayStar PowerCache
+ */
+
+inline void
+flush_daystar(void)
+{
+	if (daystar_initialized) {
+/*		printf("."); */
+		asm("tstb	0x520f0000 | flush daystar external cache");
+	}
+/*	else
+		printf ("***** Flush called before map!\n"); */
+}
+
+/*
+ * disable_daystar()
+ *
+ *   Disable external writeback cache of DayStar PowerCache
+ */
+
+inline void
+disable_daystar(void)
+{
+	asm("tstb	0x52040000 | disable writeback cache");
+	asm("tstb	0x52060000 | disable daystar external cache");
+	asm("tstb	0x520f0000 | flush daystar external cache");
+}
+
+/* 
+ * enable_daystar()
+ *
+ *   Enable external writeback cache of DayStar PowerCache
+ */
+
+inline void
+enable_daystar(void)
+{
+	disable_daystar();
+	printf("Enabling DayStar External Cache...\n");
+	asm("tstb	0x52070000 | enable daystar external cache");
+	asm("tstb	0x52050000 | enable writeback cache");
+	flush_daystar();
+}
+
+/*
+ * map_daystar()
+ *
+ *   Map DayStar PowerCache control registers in pmap
+ */
+
+inline void
+map_daystar(void)
+{
+	printf("Mapping DayStar PowerCache Hardware Addresses...\n");
+	pmap_enter (pmap_kernel(), 0x52040000, 0x52040000,
+		    VM_PROT_READ | VM_PROT_WRITE, TRUE);
+	pmap_enter (pmap_kernel(), 0x52050000, 0x52050000,
+		    VM_PROT_READ | VM_PROT_WRITE, TRUE);
+	pmap_enter (pmap_kernel(), 0x52060000, 0x52060000,
+		    VM_PROT_READ | VM_PROT_WRITE, TRUE);
+	pmap_enter (pmap_kernel(), 0x52070000, 0x52070000,
+		    VM_PROT_READ | VM_PROT_WRITE, TRUE);
+	pmap_enter (pmap_kernel(), 0x520f0000, 0x520f0000,
+		    VM_PROT_READ | VM_PROT_WRITE, TRUE);
+	daystar_initialized = TRUE;
+	enable_daystar();
+}
+#endif /* POWERCACHE_SUPPORT */
Index: sys_machdep.c
===================================================================
RCS file: /var/cvsroot/src/sys/arch/mac68k/mac68k/sys_machdep.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -u -r1.1.1.1 -r1.2
--- sys_machdep.c	1998/07/26 17:28:50	1.1.1.1
+++ sys_machdep.c	1998/09/04 00:46:13	1.2
@@ -152,6 +152,7 @@
 int	cachectl __P((int, caddr_t, int));
 void	DCIU __P((void));
 void	ICIA __P((void));
+void	PCIA __P((void));
 
 /*ARGSUSED1*/
 int
@@ -165,11 +166,18 @@
 	switch (req) {
 	case CC_EXTPURGE|CC_PURGE:
 	case CC_EXTPURGE|CC_FLUSH:
+#ifdef POWERCACHE_SUPPORT
+		PCIA(); /* flush daystar external cache */
+#endif /* POWERCACHE_SUPPORT */
+		/* fall into... */
 	case CC_PURGE:
 	case CC_FLUSH:
 		DCIU();
 		break;
 	case CC_EXTPURGE|CC_IPURGE:
+#ifdef POWERCACHE_SUPPORT
+		PCIA(); /* flush daystar external cache */
+#endif /* POWERCACHE_SUPPORT */
 		DCIU();
 		/* fall into... */
 	case CC_IPURGE:
>Audit-Trail:
>Unformatted: