Subject: Re: pmax WSCONS
To: None <port-pmax@netbsd.org>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: port-pmax
Date: 12/14/2003 17:30:54
Just FYI..

Here is a quick result on my 3MIN (which has both sfb and tfb):

sfb: WSCONS kernel boots, but only garbage (like underline) is printed.
tfb: just works.

Sprinkled "volatile" declaration to sfb.c seems to fix the problem,
but I guess the real fix is to use bus_space(9) for all register
access for sfb so that we could nuke #if defined(pmax).
---
Izumi Tsutsui
tsutsui@ceres.dti.ne.jp

Index: sfb.c
===================================================================
RCS file: /cvsroot/src/sys/dev/tc/sfb.c,v
retrieving revision 1.61
diff -u -r1.61 sfb.c
--- sfb.c	13 Nov 2003 03:09:29 -0000	1.61
+++ sfb.c	14 Dec 2003 08:20:12 -0000
@@ -261,7 +261,7 @@
 	struct wsemuldisplaydev_attach_args waa;
 	struct hwcmap256 *cm;
 	const u_int8_t *p;
-	caddr_t asic;
+	volatile caddr_t asic;
 	int console, index;
 
 	console = (ta->ta_addr == sfb_consaddr);
@@ -300,8 +300,8 @@
 	tc_intr_establish(parent, ta->ta_cookie, IPL_TTY, sfbintr, sc);
 
 	asic = (caddr_t)ri->ri_hw + SFB_ASIC_OFFSET;
-	*(u_int32_t *)(asic + SFB_ASIC_CLEAR_INTR) = 0;
-	*(u_int32_t *)(asic + SFB_ASIC_ENABLE_INTR) = 1;
+	*(volatile u_int32_t *)(asic + SFB_ASIC_CLEAR_INTR) = 0;
+	*(volatile u_int32_t *)(asic + SFB_ASIC_ENABLE_INTR) = 1;
 
 	waa.console = console;
 	waa.scrdata = &sfb_screenlist;
@@ -315,20 +315,20 @@
 sfb_common_init(ri)
 	struct rasops_info *ri;
 {
-	caddr_t base, asic;
+	volatile caddr_t base, asic;
 	int hsetup, vsetup, vbase, cookie;
 
 	base = (caddr_t)ri->ri_hw;
 	asic = base + SFB_ASIC_OFFSET;
-	hsetup = *(u_int32_t *)(asic + SFB_ASIC_VIDEO_HSETUP);
-	vsetup = *(u_int32_t *)(asic + SFB_ASIC_VIDEO_VSETUP);
+	hsetup = *(volatile u_int32_t *)(asic + SFB_ASIC_VIDEO_HSETUP);
+	vsetup = *(volatile u_int32_t *)(asic + SFB_ASIC_VIDEO_VSETUP);
 
-	*(u_int32_t *)(asic + SFB_ASIC_VIDEO_BASE) = vbase = 1;
-	*(u_int32_t *)(asic + SFB_ASIC_PLANEMASK) = ~0;
-	*(u_int32_t *)(asic + SFB_ASIC_PIXELMASK) = ~0;
-	*(u_int32_t *)(asic + SFB_ASIC_MODE) = 0;	/* MODE_SIMPLE */
-	*(u_int32_t *)(asic + SFB_ASIC_ROP) = 3; 	/* ROP_COPY */
-	*(u_int32_t *)(asic + 0x180000) = 0; 		/* Bt459 reset */
+	*(volatile u_int32_t *)(asic + SFB_ASIC_VIDEO_BASE) = vbase = 1;
+	*(volatile u_int32_t *)(asic + SFB_ASIC_PLANEMASK) = ~0;
+	*(volatile u_int32_t *)(asic + SFB_ASIC_PIXELMASK) = ~0;
+	*(volatile u_int32_t *)(asic + SFB_ASIC_MODE) = 0;	/* MODE_SIMPLE */
+	*(volatile u_int32_t *)(asic + SFB_ASIC_ROP) = 3; 	/* ROP_COPY */
+	*(volatile u_int32_t *)(asic + 0x180000) = 0; 		/* Bt459 reset */
 
 	/* initialize colormap and cursor hardware */
 	sfbhwinit(base);
@@ -532,12 +532,12 @@
 	void *arg;
 {
 	struct sfb_softc *sc = arg;
-	caddr_t base, asic, vdac;
+	volatile caddr_t base, asic, vdac;
 	int v;
 	
 	base = (caddr_t)sc->sc_ri->ri_hw;
 	asic = base + SFB_ASIC_OFFSET;
-	*(u_int32_t *)(asic + SFB_ASIC_CLEAR_INTR) = 0;
+	*(volatile u_int32_t *)(asic + SFB_ASIC_CLEAR_INTR) = 0;
 	/* *(u_int32_t *)(asic + SFB_ASIC_ENABLE_INTR) = 1; */
 
 	if (sc->sc_changed == 0)
@@ -630,7 +630,7 @@
 sfbhwinit(base)
 	caddr_t base;
 {
-	caddr_t vdac = base + SFB_RAMDAC_OFFSET;
+	volatile caddr_t vdac = base + SFB_RAMDAC_OFFSET;
 	const u_int8_t *p;
 	int i;
 
@@ -866,23 +866,23 @@
 #endif
 
 #define	SFBMODE(p, v) \
-		(*(u_int32_t *)(BUMP(p) + SFB_ASIC_MODE) = (v))
+		(*(volatile u_int32_t *)(BUMP(p) + SFB_ASIC_MODE) = (v))
 #define	SFBROP(p, v) \
-		(*(u_int32_t *)(BUMP(p) + SFB_ASIC_ROP) = (v))
+		(*(volatile u_int32_t *)(BUMP(p) + SFB_ASIC_ROP) = (v))
 #define	SFBPLANEMASK(p, v) \
-		(*(u_int32_t *)(BUMP(p) + SFB_ASIC_PLANEMASK) = (v))
+		(*(volatile u_int32_t *)(BUMP(p) + SFB_ASIC_PLANEMASK) = (v))
 #define	SFBPIXELMASK(p, v) \
-		(*(u_int32_t *)(BUMP(p) + SFB_ASIC_PIXELMASK) = (v))
+		(*(volatile u_int32_t *)(BUMP(p) + SFB_ASIC_PIXELMASK) = (v))
 #define	SFBADDRESS(p, v) \
-		(*(u_int32_t *)(BUMP(p) + SFB_ASIC_ADDRESS) = (v))
+		(*(volatile u_int32_t *)(BUMP(p) + SFB_ASIC_ADDRESS) = (v))
 #define	SFBSTART(p, v) \
-		(*(u_int32_t *)(BUMP(p) + SFB_ASIC_START) = (v))
+		(*(volatile u_int32_t *)(BUMP(p) + SFB_ASIC_START) = (v))
 #define	SFBPIXELSHIFT(p, v) \
-		(*(u_int32_t *)(BUMP(p) + SFB_ASIC_PIXELSHIFT) = (v))
+		(*(volatile u_int32_t *)(BUMP(p) + SFB_ASIC_PIXELSHIFT) = (v))
 #define	SFBFG(p, v) \
-		(*(u_int32_t *)(BUMP(p) + SFB_ASIC_FG) = (v))
+		(*(volatile u_int32_t *)(BUMP(p) + SFB_ASIC_FG) = (v))
 #define	SFBBG(p, v) \
-		(*(u_int32_t *)(BUMP(p) + SFB_ASIC_BG) = (v))
+		(*(volatile u_int32_t *)(BUMP(p) + SFB_ASIC_BG) = (v))
 
 /*
  * Paint the cursor.
@@ -891,7 +891,7 @@
 sfb_do_cursor(ri)
 	struct rasops_info *ri;
 {
-	caddr_t sfb, p;
+	volatile caddr_t sfb, p;
 	int scanspan, height, width, align, x, y;
 	u_int32_t lmask, rmask;
 
@@ -935,7 +935,7 @@
 	long attr;
 {
 	struct rasops_info *ri = id;
-	caddr_t sfb, p;
+	volatile caddr_t sfb, p;
 	int scanspan, height, width, align, x, y;
 	u_int32_t lmask, rmask, glyph;
 	u_int8_t *g;
@@ -992,7 +992,7 @@
 	int row, srccol, dstcol, ncols;
 {
 	struct rasops_info *ri = id;
-	caddr_t sp, dp, basex, sfb;
+	volatile caddr_t sp, dp, basex, sfb;
 	int scanspan, height, width, aligns, alignd, shift, w, y;
 	u_int32_t lmaskd, rmaskd;
 
@@ -1019,8 +1019,8 @@
 		sp -= aligns;
 		dp -= alignd;
 		while (height > 0) {
-			*(u_int32_t *)sp = SFBCOPYALL1;	WRITE_MB();
-			*(u_int32_t *)dp = lmaskd;	WRITE_MB();
+			*(volatile u_int32_t *)sp = SFBCOPYALL1;	WRITE_MB();
+			*(volatile u_int32_t *)dp = lmaskd;	WRITE_MB();
 			sp += scanspan;
 			dp += scanspan;
 			height--;
@@ -1046,20 +1046,20 @@
 		sq = sp;
 		dq = dp;
 		while (height > 0) {
-			*(u_int32_t *)sp = SFBCOPYALL1;	WRITE_MB();
-			*(u_int32_t *)dp = lmaskd;	WRITE_MB();
+			*(volatile u_int32_t *)sp = SFBCOPYALL1;	WRITE_MB();
+			*(volatile u_int32_t *)dp = lmaskd;	WRITE_MB();
 			width -= 2 * SFBCOPYBITS;
 			while (width > 0) {
 				sp += SFBCOPYBYTESDONE;
 				dp += SFBCOPYBYTESDONE;
-				*(u_int32_t *)sp = SFBCOPYALL1; WRITE_MB();
-				*(u_int32_t *)dp = SFBCOPYALL1; WRITE_MB();
+				*(volatile u_int32_t *)sp = SFBCOPYALL1; WRITE_MB();
+				*(volatile u_int32_t *)dp = SFBCOPYALL1; WRITE_MB();
 				width -= SFBCOPYBITS;
 			}
 			sp += SFBCOPYBYTESDONE;
 			dp += SFBCOPYBYTESDONE;
-			*(u_int32_t *)sp = SFBCOPYALL1;	WRITE_MB();
-			*(u_int32_t *)dp = rmaskd;	WRITE_MB();
+			*(volatile u_int32_t *)sp = SFBCOPYALL1;	WRITE_MB();
+			*(volatile u_int32_t *)dp = rmaskd;	WRITE_MB();
 			sp = (sq += scanspan);
 			dp = (dq += scanspan);
 			width = w;
@@ -1086,20 +1086,20 @@
 		sq = sp += (((aligns + w) - 1) & ~31);
 		dq = dp += (((alignd + w) - 1) & ~31);
 		while (height > 0) {
-			*(u_int32_t *)sp = SFBCOPYALL1; WRITE_MB();
-			*(u_int32_t *)dp = rmaskd;	WRITE_MB();
+			*(volatile u_int32_t *)sp = SFBCOPYALL1; WRITE_MB();
+			*(volatile u_int32_t *)dp = rmaskd;	WRITE_MB();
 			width -= 2 * SFBCOPYBITS;
 			while (width > 0) {
 				sp -= SFBCOPYBYTESDONE;
 				dp -= SFBCOPYBYTESDONE;
-				*(u_int32_t *)sp = SFBCOPYALL1; WRITE_MB();
-				*(u_int32_t *)dp = SFBCOPYALL1; WRITE_MB();
+				*(volatile u_int32_t *)sp = SFBCOPYALL1; WRITE_MB();
+				*(volatile u_int32_t *)dp = SFBCOPYALL1; WRITE_MB();
 				width -= SFBCOPYBITS;
 			}
 			sp -= SFBCOPYBYTESDONE;
 			dp -= SFBCOPYBYTESDONE;
-			*(u_int32_t *)sp = SFBCOPYALL1;	WRITE_MB();
-			*(u_int32_t *)dp = lmaskd;	WRITE_MB();
+			*(volatile u_int32_t *)sp = SFBCOPYALL1;	WRITE_MB();
+			*(volatile u_int32_t *)dp = lmaskd;	WRITE_MB();
 
 			sp = (sq += scanspan);
 			dp = (dq += scanspan);
@@ -1122,7 +1122,7 @@
 	long attr;
 {
 	struct rasops_info *ri = id;
-	caddr_t sfb, p;
+	volatile caddr_t sfb, p;
 	int scanspan, startx, height, width, align, w, y;
 	u_int32_t lmask, rmask;
 
@@ -1155,17 +1155,17 @@
 	else {
 		caddr_t q = p;
 		while (height > 0) {
-			*(u_int32_t *)p = lmask;
+			*(volatile u_int32_t *)p = lmask;
 			WRITE_MB();
 			width -= 2 * SFBSTIPPLEBITS;
 			while (width > 0) {
 				p += SFBSTIPPLEBYTESDONE;
-				*(u_int32_t *)p = SFBSTIPPLEALL1;
+				*(volatile u_int32_t *)p = SFBSTIPPLEALL1;
 				WRITE_MB();
 				width -= SFBSTIPPLEBITS;
 			}
 			p += SFBSTIPPLEBYTESDONE;
-			*(u_int32_t *)p = rmask;
+			*(volatile u_int32_t *)p = rmask;
 			WRITE_MB();
 
 			p = (q += scanspan);
@@ -1185,7 +1185,7 @@
 	int srcrow, dstrow, nrows;
 {
 	struct rasops_info *ri = id;
-	caddr_t sfb, p;
+	volatile caddr_t sfb, p;
 	int scanspan, offset, srcy, height, width, align, w;
 	u_int32_t lmask, rmask;
 
@@ -1216,18 +1216,18 @@
 	else {
 		caddr_t q = p;
 		while (height > 0) {
-			*(u_int32_t *)p = lmask;
-			*(u_int32_t *)(p + offset) = lmask;
+			*(volatile u_int32_t *)p = lmask;
+			*(volatile u_int32_t *)(p + offset) = lmask;
 			width -= 2 * SFBCOPYBITS;
 			while (width > 0) {
 				p += SFBCOPYBYTESDONE;
-				*(u_int32_t *)p = SFBCOPYALL1;
-				*(u_int32_t *)(p + offset) = SFBCOPYALL1;
+				*(volatile u_int32_t *)p = SFBCOPYALL1;
+				*(volatile u_int32_t *)(p + offset) = SFBCOPYALL1;
 				width -= SFBCOPYBITS;
 			}
 			p += SFBCOPYBYTESDONE;
-			*(u_int32_t *)p = rmask;
-			*(u_int32_t *)(p + offset) = rmask;
+			*(volatile u_int32_t *)p = rmask;
+			*(volatile u_int32_t *)(p + offset) = rmask;
 
 			p = (q += scanspan);
 			width = w + align;
@@ -1247,7 +1247,7 @@
 	long attr;
 {
 	struct rasops_info *ri = id;
-	caddr_t sfb, p;
+	volatile caddr_t sfb, p;
 	int scanspan, starty, height, width, align, w;
 	u_int32_t lmask, rmask;
 
@@ -1273,17 +1273,17 @@
 	else {
 		caddr_t q = p;
 		while (height > 0) {
-			*(u_int32_t *)p = lmask;
+			*(volatile u_int32_t *)p = lmask;
 			WRITE_MB();
 			width -= 2 * SFBSTIPPLEBITS;
 			while (width > 0) {
 				p += SFBSTIPPLEBYTESDONE;
-				*(u_int32_t *)p = SFBSTIPPLEALL1;
+				*(volatile u_int32_t *)p = SFBSTIPPLEALL1;
 				WRITE_MB();
 				width -= SFBSTIPPLEBITS;
 			}
 			p += SFBSTIPPLEBYTESDONE;
-			*(u_int32_t *)p = rmask;
+			*(volatile u_int32_t *)p = rmask;
 			WRITE_MB();
 
 			p = (q += scanspan);