Subject: port-next68k/6709: add bus_space support for mono framebuffer
To: None <gnats-bugs@gnats.netbsd.org>
From: None <deberg@MIT.EDU>
List: netbsd-bugs
Date: 01/02/1999 02:13:29
>Number:         6709
>Category:       port-next68k
>Synopsis:       add bus_space support for mono framebuffer
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    port-next68k-maintainer (NetBSD/next68k Portmaster)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Jan  1 23:20:00 1999
>Last-Modified:
>Originator:     matt debergalis
>Organization:
matt debergalis <deberg@mit.edu> KB1CTH
finger deberg@ai.mit.edu for PGP key
>Release:        -current 19990101
>Environment:
System: NetBSD pizzabox.deberg.org 1.3I NetBSD 1.3I (WSCONS) #38: Sat Jan  2 00:10:13 EST 1999     deberg@sunrise.ne.mediaone.net:/src/netbsd/src/sys/arch/next68k/compile/WSCONS next68k

>Description:
        need to access framebuffer memory
>How-To-Repeat:
>Fix:
Index: genassym.cf
===================================================================
RCS file: /src/cvsroot-netbsd/netbsd/src/sys/arch/next68k/next68k/genassym.cf,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 genassym.cf
--- genassym.cf	1998/11/12 21:30:55	1.1.1.3
+++ genassym.cf	1999/01/01 19:00:34
@@ -157,6 +157,8 @@
 define	FC_USERD		FC_USERD
 define	INTIOBASE		INTIOBASE
 define	INTIOTOP                INTIOTOP
+define  VIDEOBASE               VIDEOBASE
+define  VIDEOTOP                VIDEOTOP
 define	IIOMAPSIZE		IIOMAPSIZE
 define	CACHE_ON		CACHE_ON
 define	CACHE_OFF		CACHE_OFF
Index: locore.s
===================================================================
RCS file: /src/cvsroot-netbsd/netbsd/src/sys/arch/next68k/next68k/locore.s,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 locore.s
--- locore.s	1998/12/01 03:19:22	1.1.1.4
+++ locore.s	1999/01/02 07:11:43
@@ -1868,6 +1868,12 @@
 GLOBAL(intiolimit)
 	.long	INTIOTOP        | KVA of end of internal IO space
 
+GLOBAL(videobase)
+	.long	VIDEOBASE       | KVA of base of mono FB
+
+GLOBAL(videolimit)
+	.long	VIDEOTOP        | KVA of end of mono FB
+
 ASLOCAL(save_vbr)               | VBR from ROM
         .long 0xdeadbeef
Index: pmap.c
===================================================================
RCS file: /src/cvsroot-netbsd/netbsd/src/sys/arch/next68k/next68k/pmap.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 pmap.c
--- pmap.c	1998/11/09 23:13:37	1.1.1.2
+++ pmap.c	1999/01/01 19:14:37
@@ -391,6 +391,13 @@
 				UVM_INH_NONE, UVM_ADV_RANDOM,
 				UVM_FLAG_FIXED)) != KERN_SUCCESS)
 		goto bogons;
+	addr = (vaddr_t) videobase;
+	if (uvm_map(kernel_map, &addr, m68k_ptob(VIDEOMAPSIZE),
+		    NULL, UVM_UNKNOWN_OFFSET,
+		    UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE,
+				UVM_INH_NONE, UVM_ADV_RANDOM,
+				UVM_FLAG_FIXED)) != KERN_SUCCESS)
+		goto bogons;
 	addr = (vaddr_t) Sysmap;
 	if (uvm_map(kernel_map, &addr, HP_MAX_PTSIZE,
 		    NULL, UVM_UNKNOWN_OFFSET,
@@ -411,6 +418,11 @@
 			   &addr, m68k_ptob(IIOMAPSIZE), FALSE);
 	if (addr != (vaddr_t)intiobase)
 		goto bogons;
+	addr = (vaddr_t) videobase;
+	(void) vm_map_find(kernel_map, NULL, (vaddr_t) 0,
+			   &addr, m68k_ptob(VIDEOMAPSIZE), FALSE);
+	if (addr != (vaddr_t)videobase)
+		goto bogons;
 	addr = (vaddr_t) Sysmap;
 	vm_object_reference(kernel_object);
 	(void) vm_map_find(kernel_map, kernel_object, addr,
@@ -2532,7 +2544,7 @@
 				 * flushed (but only once).
 				 */
 				if (firstpage && mmutype == MMU_68040 &&
-				    (bit == PG_RO && setem ||
+				    ((bit == PG_RO && setem) ||
 				     (bit & PG_CMASK))) {
 					firstpage = FALSE;
 					DCFP(pa);
@@ -2783,7 +2795,7 @@
 		do {
 			if (pv->pv_pmap == pmap_kernel() && pv->pv_va == va)
 				break;
-		} while (pv = pv->pv_next);
+		} while ((pv = pv->pv_next));
 	}
 #ifdef DEBUG
 	if (pv == NULL)
Index: pmap_bootstrap.c
===================================================================
RCS file: /src/cvsroot-netbsd/netbsd/src/sys/arch/next68k/next68k/pmap_bootstrap.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 pmap_bootstrap.c
--- pmap_bootstrap.c	1998/09/20 00:14:55	1.1.1.1
+++ pmap_bootstrap.c	1999/01/02 04:08:04
@@ -110,6 +110,7 @@
 	paddr_t firstpa;
 {
 	paddr_t kstpa, kptpa, eiiopa, iiopa, kptmpa, lkptpa, p0upa;
+        paddr_t evpa, vpa;
 	u_int nptpages, kstsize;
 	st_entry_t protoste, *ste;
 	pt_entry_t protopte, *pte, *epte;
@@ -130,6 +131,12 @@
 	 *
 	 *	eiiopa		page following
 	 *			internal IO space
+         *
+         *      vpa             video fb PT pages       VIDEOSIZE pages
+         *   
+         *      evpa            page following
+         *                      video fb pages
+         *
 	 *
 	 * [ Sysptsize is the number of pages of PT, and IIOMAPSIZE
 	 *   is the number of PTEs, hence we need to round
@@ -152,10 +159,14 @@
 	nextpa += kstsize * NBPG;
 	kptpa = nextpa;
 	nptpages = RELOC(Sysptsize, int) +
-		(IIOMAPSIZE + NPTEPG - 1) / NPTEPG;
+		(IIOMAPSIZE + VIDEOMAPSIZE + NPTEPG - 1) / NPTEPG;
 	nextpa += nptpages * NBPG;
 	eiiopa = nextpa;		/* just a reference for later */
 	iiopa = nextpa - IIOMAPSIZE * sizeof(pt_entry_t);
+        
+        evpa = nextpa - IIOMAPSIZE * sizeof(pt_entry_t);
+        vpa = evpa - VIDEOMAPSIZE * sizeof(pt_entry_t);
+
 	kptmpa = nextpa;
 	nextpa += NBPG;
 	lkptpa = nextpa;
@@ -370,6 +381,15 @@
 		protopte += NBPG;
 	}
 
+        /* validate the video fb space PTEs */
+	pte = (u_int *)vpa;
+	epte = (u_int *)evpa;
+	protopte = VIDEOBASE | PG_RW | PG_CI | PG_V;
+	while (pte < epte) {
+		*pte++ = protopte;
+		protopte += NBPG;
+	}
+
 	/*
 	 * Calculate important exported kernel virtual addresses
 	 */
@@ -389,6 +409,17 @@
 	 */
 	RELOC(Sysmap, pt_entry_t *) =
 		(pt_entry_t *)m68k_ptob(nptpages * NPTEPG);
+
+	/*
+	 * videobase, videolimit: base and end of video fb space.
+	 * VIDEOMAPSIZE pages prior to external IO space at end of static
+	 * kernel page table.
+	 */
+	RELOC(videobase, char *) =
+		(char *)m68k_ptob(nptpages*NPTEPG - IIOMAPSIZE - VIDEOMAPSIZE);
+	RELOC(videolimit, char *) =
+		(char *)m68k_ptob(nptpages*NPTEPG - IIOMAPSIZE);
+
 	/*
 	 * intiobase, intiolimit: base and end of internal IO space.
 	 * IIOMAPSIZE pages prior to external IO space at end of static
Index: bus_space.h
===================================================================
RCS file: /src/cvsroot-netbsd/netbsd/src/sys/arch/next68k/include/bus_space.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 bus_space.h
--- bus_space.h	1998/09/20 00:14:52	1.1.1.1
+++ bus_space.h	1999/01/01 20:04:38
@@ -83,11 +83,19 @@
 #define NEXT68K_INTIO_BUS_SPACE	intiobase
 
 /*
+ * Value for the next68k video bus space tag, not to be used directly by MI code.
+ */
+#define NEXT68K_VIDEO_BUS_SPACE	videobase
+
+/*
  * Mapping and unmapping operations.
  */
 #define	bus_space_map(t, a, s, f, hp)					\
     ((((a)>=INTIOBASE)&&((a)+(s)<INTIOTOP)) ?				\
-     ((*(hp)=(bus_space_handle_t)((t)+((a)-INTIOBASE))),0) : (-1))
+     ((*(hp)=(bus_space_handle_t)((t)+((a)-INTIOBASE))),0) :            \
+     ((((a)>=VIDEOBASE)&&((a)+(s)<VIDEOTOP)) ?                          \
+      ((*(hp)=(bus_space_handle_t)((t)+((a)-VIDEOBASE))),0) :           \
+      (-1)))
 
 #define	bus_space_unmap(t, h, s)
 	
Index: cpu.h
===================================================================
RCS file: /src/cvsroot-netbsd/netbsd/src/sys/arch/next68k/include/cpu.h,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 cpu.h
--- cpu.h	1998/11/12 21:30:50	1.1.1.2
+++ cpu.h	1999/01/01 20:37:09
@@ -120,6 +120,8 @@
 #ifdef _KERNEL
 extern	volatile char *intiobase;
 extern  volatile char *intiolimit;
+extern	volatile char *videobase;
+extern  volatile char *videolimit;
 extern	void (*vectab[]) __P((void));
 
 struct frame;
@@ -363,7 +365,9 @@
 
 #define	INTIOBASE	(0x02000000)
 #define	INTIOTOP	(0x02120000)
-
+#define VIDEOBASE       (0x0b000000)
+#define VIDEOTOP        (0x0b03a800)
+                                     
 #define NEXT_INTR_BITS \
 "\20\40NMI\37PFAIL\36TIMER\35ENETX_DMA\34ENETR_DMA\33SCSI_DMA\32DISK_DMA\31PRINTER_DMA\30SOUND_OUT_DMA\27SOUND_IN_DMA\26SCC_DMA\25DSP_DMA\24M2R_DMA\23R2M_DMA\22SCC\21REMOTE\20BUS\17DSP_4\16DISK|C16_VIDEO\15SCSI\14PRINTER\13ENETX\12ENETR\11SOUND_OVRUN\10PHONE\07DSP_3\06VIDEO\05MONITOR\04KYBD_MOUSE\03POWER\02SOFTINT1\01SOFTINT0"
 
@@ -382,5 +386,13 @@
 #define	IIOP(va)	((int)(va)-(int)intiobase+INTIOBASE)
 #define	IIOPOFF(pa)	((int)(pa)-INTIOBASE)
 #define	IIOMAPSIZE	btoc(INTIOTOP-INTIOBASE)	/* 2mb */
+
+/* video fb space */
+#define	ISVIDEOVA(va) \
+	((char *)(va) >= videobase && (char *)(va) < videolimit)
+#define	VIDEOV(pa)	((int)(pa)-VIDEOBASE+(int)videobase)
+#define	VIDEOP(va)	((int)(va)-(int)videobase+VIDEOBASE)
+#define	VIDEOPOFF(pa)	((int)(pa)-VIDEOBASE)
+#define	VIDEOMAPSIZE	btoc(VIDEOTOP-VIDEOBASE)	/* who cares */
 
 #endif	/* _CPU_MACHINE_ */
>Audit-Trail:
>Unformatted: