Subject: Daystar '030 patch & questions
To: NetBSD/mac68k list <port-mac68k@netbsd.org>
From: John Valdes <valdes@uchicago.edu>
List: port-mac68k
Date: 01/09/2002 21:45:05
--bg08WKrSYDhXBjb5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Folks,

Attached below is a copy of the Daystar '030 Universal PowerCache
patch that's been floating around since NetBSD 1.3, updated to patch
against 1.5.2 kernel sources.  This patch enables the 32KB external
cache that resides on the PowerCache card.

There are no significant changes to the patch at this point other than
updating it for the newer calling interface on pmap_enter and the
changes in line numbers.  The only other change: I changed the name of
the preprocessor directive used from "DAYSTAR" to "DAYSTAR_030", since
there are Daystar '040 accelerators out there, and this patch doesn't
apply to them.

To use, apply the patch to the files in
/usr/src/sys/arch/mac68k/mac68k, add "options DAYSTAR_030" to your
kernel config file, and rebuild the kernel.  I've been using a patched
kernel now for about a week on my IIcx w/ 50MHz Daystar '030 with no
problems so far.  I had previously been using this patch under 1.4
for > 2 years w/o problem.

That said, I'd like to implement the changes suggested by Allen Briggs
back in June of 1999 (see the thread "question about pmap_enter()"
from June 5-10, 1999 in the archives) so that the patch can *at last*
be rolled into the main kernel sources. :)  Back then, the consensus
was: 

Allen Briggs writes:
> I ran across these patches while browsing through the PRs and there's
> one drawback to getting them into the repository.  They'll break on
> systems that don't have a Daystar installed.  Scott might have other
> ideas, but I see basically three approaches:
> 
> [ In any of them, you'll have to probe for a Daystar by checking to see
>   if a read to any of the memory locations generates a bus error. ]
>
>       1) (my favorite) If there is no Daystar, map a single page of
>          memory over the 5 pages where the Daystar lives, then use
>          the same code everywhere.  It's a minor hit on systems that
>          don't have a Daystar, but it keeps everything pretty clean.

This seems doable, but I have some questions:

1) How do I catch a bus error in the kernel?  In userland, I would use
   signal() to set a signal handler for SIGBUS, setjmp() to define a
   jump point, and then in the signal handler, use longjmp() to return
   to the jump point.  Does this work in the kernel?

2) How do I map a single page of memory over the 5 Daystar pages, and
   what page of memory should I use for this?  Presumedly I just use
   pmap_enter() and specify the same physical page address for all 5
   virtual page addresses.

John

--bg08WKrSYDhXBjb5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="daystar152.patch"

*** locore.s.orig	Thu Jan 25 11:39:18 2001
--- locore.s	Mon Dec 31 12:10:48 2001
***************
*** 123,128 ****
--- 123,132 ----
  
  BSS(esym,4)
  
+ #ifdef DAYSTAR_030
+ 	.globl	_disable_daystar	| in pmap.c /* kmr */
+ #endif
+ 
  ASENTRY_NOPROFILE(start)
  	movw	#PSL_HIGHIPL,sr		| no interrupts.  ever.
  	lea	_ASM_LABEL(tmpstk),sp	| give ourselves a temporary stack
***************
*** 154,159 ****
--- 158,167 ----
  	tstl	d0			| zero?
  	jeq	Lnot68030		| yes, we have 68020/68040
  
+ #ifdef DAYSTAR_030
+ 	jbsr    _disable_daystar        | Disable daystar external cache /* kmr */
+ #endif
+ 
  	movl	#CACHE_OFF,d0		| disable and clear both caches
  	movc	d0,cacr
  	lea	_C_LABEL(mmutype),a0	| no, we have 68030
***************
*** 315,324 ****
--- 323,341 ----
  
  /* flush TLB and turn on caches */
  	jbsr	_C_LABEL(TBIA)		| invalidate TLB
+ 
+ #ifdef DAYSTAR_030
+         .globl  _flush_daystar /* kmr */
+ #endif
+ 
  	cmpl	#MMU_68040,_C_LABEL(mmutype) | 68040?
  	jeq	Lnocache0		| yes, cache already on
  	movl	#CACHE_ON,d0
  	movc	d0,cacr			| clear cache(s)
+ #ifdef DAYSTAR_030
+         jbsr    _flush_daystar          | flush daystar external cache /* kmr */
+ #endif
+ 
  #ifdef __notyet__
  	tstl	_C_LABEL(ectype)
  	jeq	Lnocache0
***************
*** 1213,1224 ****
--- 1230,1248 ----
  	movl	#DC_CLEAR,d0
  	movc	d0,cacr			| invalidate on-chip d-cache
  Ltbia851:
+ #ifdef DAYSTAR_030
+         jbsr    _flush_daystar          | flush daystar external cache /* kmr */
+ #endif
  	rts
  
  /*
   * Invalidate any TLB entry for given VA (TB Invalidate Single)
   */
  ENTRY(TBIS)
+ #ifdef DAYSTAR_030
+         .globl  _flush_daystar /* kmr */
+ #endif
+ 
  #ifdef DEBUG
  	tstl	_ASM_LABEL(fulltflush)	| being conservative?
  	jne	_C_LABEL(_TBIA)		| yes, flush entire TLB
***************
*** 1248,1259 ****
--- 1272,1291 ----
  	pflush	#0,#0,a0@		| flush address from both sides
  	movl	#DC_CLEAR,d0
  	movc	d0,cacr			| invalidate on-chip data cache
+ #ifdef DAYSTAR_030
+         jbsr    _flush_daystar          | flush daystar external cache /* kmr */
+ #endif
  	rts
  
  /*
   * Invalidate supervisor side of TLB
   */
  ENTRY(TBIAS)
+ 
+ #ifdef DAYSTAR_030
+         .globl  _flush_daystar /* kmr */
+ #endif
+ 
  #ifdef DEBUG
  	tstl	_ASM_LABEL(fulltflush)	| being conservative?
  	jne	_C_LABEL(_TBIA)		| yes, flush everything
***************
*** 1275,1286 ****
--- 1307,1326 ----
  	pflush	#4,#4			| flush supervisor TLB entries
  	movl	#DC_CLEAR,d0
  	movc	d0,cacr			| invalidate on-chip d-cache
+ 
+ #ifdef DAYSTAR_030
+         jbsr    _flush_daystar          | flush daystar external cache /* kmr */
+ #endif
+ 
  	rts
  
  /*
   * Invalidate user side of TLB
   */
  ENTRY(TBIAU)
+ #ifdef DAYSTAR_030
+         .globl  _flush_daystar /* kmr */
+ #endif
  #ifdef DEBUG
  	tstl	_ASM_LABEL(fulltflush)	| being conservative?
  	jne	_C_LABEL(_TBIA)		| yes, flush everything
***************
*** 1301,1306 ****
--- 1341,1351 ----
  	pflush	#0,#4			| flush user TLB entries
  	movl	#DC_CLEAR,d0
  	movc	d0,cacr			| invalidate on-chip d-cache
+ 
+ #ifdef DAYSTAR_030
+         jbsr    _flush_daystar          | flush daystar external cache /* kmr */
+ #endif
+ 
  	rts
  
  /*
***************
*** 1387,1392 ****
--- 1432,1442 ----
  #endif /* M68040 */
  
  ENTRY(PCIA)
+ 
+ #ifdef DAYSTAR_030
+         .globl  _flush_daystar /* kmr */
+ #endif
+ 
  #if defined(M68040)
  ENTRY(DCFA)
  	cmpl	#MMU_68040,_C_LABEL(mmutype) | 68040?
***************
*** 1397,1402 ****
--- 1447,1457 ----
  #endif
  	movl	#DC_CLEAR,d0
  	movc	d0,cacr			| invalidate on-chip d-cache
+ 
+ #ifdef DAYSTAR_030
+         jbsr    _flush_daystar          | flush daystar external cache /* kmr */
+ #endif
+ 
  	rts
  
  ENTRY(ecacheon)
*** pmap.c.orig	Sun Mar 26 14:42:29 2000
--- pmap.c	Mon Dec 31 13:37:12 2001
***************
*** 264,269 ****
--- 264,273 ----
  TAILQ_HEAD(pv_page_list, pv_page) pv_page_freelist;
  int		pv_nfree;
  
+ #ifdef DAYSTAR_030
+ boolean_t	daystar_initialized = FALSE;	/* Has map_daystar completed? */
+ #endif
+ 
  /* The following four variables are defined in pmap_bootstrap.c */
  extern int		vidlen;
  #define VIDMAPSIZE	btoc(vidlen)
***************
*** 315,320 ****
--- 319,331 ----
  void	pmap_pinit __P((pmap_t));
  void	pmap_release __P((pmap_t));
  
+ #ifdef DAYSTAR_030
+ void  flush_daystar	__P((void));
+ void  disable_daystar	__P((void));
+ void  enable_daystar	__P((void));
+ void  map_daystar	__P((void));
+ #endif
+ 
  #ifdef DEBUG
  void	pmap_pvdump          __P((paddr_t));
  void	pmap_check_wiring    __P((char *, vaddr_t));
***************
*** 325,330 ****
--- 336,395 ----
  #define	PRM_CFLUSH	0x02
  #define	PRM_KEEPPTPAGE	0x04
  
+ #ifdef DAYSTAR_030
+ void
+ flush_daystar()
+ {
+         if (daystar_initialized) {
+ /*        printf("."); */
+           asm ("tstb    0x520F0000 | flush daystar external cache");
+         }
+ /*      else
+           printf("***** Flush called before map!\n"); */
+ }
+ 
+ void
+ disable_daystar()
+ {
+         asm ("tstb      0x52040000 | disable writeback cache");
+         asm ("tstb      0x52060000 | disable daystar external cache");
+         asm ("tstb      0x520F0000 | flush daystar external cache");
+ }
+ 
+ void
+ enable_daystar()
+ {
+         disable_daystar();
+         printf("Enabling Daystar External Cache...\n");
+         asm ("tstb      0x52070000 | enable daystar external cache");
+         asm ("tstb      0x52050000 | enable daystar writeback cache");
+         flush_daystar();
+ }
+ 
+ void
+ map_daystar()
+ {
+         printf("Mapping Daystar Hardware Addresses...\n");
+         pmap_enter (pmap_kernel(), 0x52040000, 0x52040000,
+                     VM_PROT_READ | VM_PROT_WRITE,
+                     VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
+         pmap_enter (pmap_kernel(), 0x52050000, 0x52050000,
+                     VM_PROT_READ | VM_PROT_WRITE,
+                     VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
+         pmap_enter (pmap_kernel(), 0x52060000, 0x52060000,
+                     VM_PROT_READ | VM_PROT_WRITE,
+                     VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
+         pmap_enter (pmap_kernel(), 0x52070000, 0x52070000,
+                     VM_PROT_READ | VM_PROT_WRITE,
+                     VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
+         pmap_enter (pmap_kernel(), 0x520F0000, 0x520F0000,
+                     VM_PROT_READ | VM_PROT_WRITE,
+                     VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED); 
+         daystar_initialized = TRUE;
+         enable_daystar();
+ }
+ #endif /* DAYSTAR_030 */
+ 
  /*
   * pmap_virtual_space:		[ INTERFACE ]
   *
***************
*** 509,514 ****
--- 574,586 ----
  
  	PMAP_DPRINTF(PDB_INIT, ("pmap_init: KPT: %ld pages from %lx to %lx\n",
  	    atop(s), addr, addr + s));
+ 
+ #ifdef DAYSTAR_030
+         /*
+          * Map physical memory addresses used by daystar accelerator
+          */
+         map_daystar();
+ #endif
  
  	/*
  	 * Allocate the segment table map and the page table map.
*** sys_machdep.c.orig	Sun Dec 12 02:18:49 1999
--- sys_machdep.c	Mon Dec 31 12:11:55 2001
***************
*** 221,226 ****
--- 221,229 ----
  			}
  			switch (req) {
  			case CC_EXTPURGE|CC_IPURGE:
+ #ifdef DAYSTAR_030
+ 				PCIA(); /* flush daystar external cache */
+ #endif
  			case CC_IPURGE:
  				if (doall) {
  					DCFA();
***************
*** 235,240 ****
--- 238,246 ----
  				break;
  			
  			case CC_EXTPURGE|CC_PURGE:
+ #ifdef DAYSTAR_030
+ 				PCIA(); /* flush daystar external cache */
+ #endif
  			case CC_PURGE:
  				if (doall)
  					DCFA();	/* note: flush not purge */
***************
*** 245,250 ****
--- 251,259 ----
  				break;
  
  			case CC_EXTPURGE|CC_FLUSH:
+ #ifdef DAYSTAR_030
+ 				PCIA(); /* flush daystar external cache */
+ #endif
  			case CC_FLUSH:
  				if (doall)
  					DCFA();

--bg08WKrSYDhXBjb5--