Module Name:    src
Committed By:   macallan
Date:           Fri Aug  4 23:54:46 UTC 2017

Modified Files:
        src/sys/dev/sbus: mgx.c

Log Message:
- store bitmap fonts in vram
- don't try to force buffer flushes
- avoid 64bit writes to vram
-> no more corruption of font bitmaps


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/sbus/mgx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sbus/mgx.c
diff -u src/sys/dev/sbus/mgx.c:1.11 src/sys/dev/sbus/mgx.c:1.12
--- src/sys/dev/sbus/mgx.c:1.11	Sat Jul 29 03:32:00 2017
+++ src/sys/dev/sbus/mgx.c	Fri Aug  4 23:54:46 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mgx.c,v 1.11 2017/07/29 03:32:00 macallan Exp $ */
+/*	$NetBSD: mgx.c,v 1.12 2017/08/04 23:54:46 macallan Exp $ */
 
 /*-
  * Copyright (c) 2014 Michael Lorenz
@@ -29,7 +29,7 @@
 /* a console driver for the SSB 4096V-MGX graphics card */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mgx.c,v 1.11 2017/07/29 03:32:00 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mgx.c,v 1.12 2017/08/04 23:54:46 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -94,6 +94,7 @@ struct mgx_softc {
 	struct wsscreen_list sc_screenlist;
 	struct vcons_data vd;
 	glyphcache 	sc_gc;
+	uint8_t		sc_in[256];
 };
 
 static int	mgx_match(device_t, cfdata_t, void *);
@@ -110,7 +111,7 @@ static int	mgx_putcmap(struct mgx_softc 
 static int 	mgx_getcmap(struct mgx_softc *, struct wsdisplay_cmap *);
 static int	mgx_wait_engine(struct mgx_softc *);
 __unused static int	mgx_wait_host(struct mgx_softc *);
-static int	mgx_wait_fifo(struct mgx_softc *, unsigned int);
+/*static*/ int	mgx_wait_fifo(struct mgx_softc *, unsigned int);
 
 static void	mgx_bitblt(void *, int, int, int, int, int, int, int);
 static void 	mgx_rectfill(void *, int, int, int, int, long);
@@ -122,6 +123,7 @@ static void	mgx_copycols(void *, int, in
 static void	mgx_erasecols(void *, int, int, int, long);
 static void	mgx_copyrows(void *, int, int, int);
 static void	mgx_eraserows(void *, int, int, long);
+static void	mgx_adapt(struct vcons_screen *, void *);
 
 static int	mgx_do_cursor(struct mgx_softc *, struct wsdisplay_cursor *);
 static void	mgx_set_cursor(struct mgx_softc *);
@@ -237,7 +239,7 @@ mgx_attach(device_t parent, device_t sel
 	struct rasops_info *ri;
 	unsigned long defattr;
 	bus_space_handle_t bh;
-	int node = sa->sa_node;
+	int node = sa->sa_node, bsize;
 	int isconsole;
 
 	aprint_normal("\n");
@@ -267,7 +269,7 @@ mgx_attach(device_t parent, device_t sel
 		}
 		sc->sc_fbaddr = bus_space_vaddr(sa->sa_bustag, bh);
 	}
-		
+
 	if (sbus_bus_map(sa->sa_bustag,
 			 sa->sa_slot,
 			 sa->sa_reg[4].oa_base, 0x1000, 0,
@@ -318,8 +320,8 @@ mgx_attach(device_t parent, device_t sel
 
 	vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr, &mgx_accessops);
 	sc->vd.init_screen = mgx_init_screen;
-	sc->vd.show_screen_cookie = &sc->sc_gc;
-	sc->vd.show_screen_cb = glyphcache_adapt;
+	sc->vd.show_screen_cookie = sc;
+	sc->vd.show_screen_cb = mgx_adapt;
 
 	vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1, &defattr);
 	sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
@@ -340,9 +342,10 @@ mgx_attach(device_t parent, device_t sel
 	 * leave some room between visible screen and glyph cache for upload
 	 * buffers used by putchar_mono()
 	 */
+	bsize = (32 * 1024 * sc->sc_stride - 1) / sc->sc_stride;
 	glyphcache_init(&sc->sc_gc,
-	    sc->sc_height + 5,
-	    (0x400000 / sc->sc_stride) - sc->sc_height - 5,
+	    sc->sc_height + bsize,
+	    (0x400000 / sc->sc_stride) - (sc->sc_height + bsize),
 	    sc->sc_width,
 	    ri->ri_font->fontwidth,
 	    ri->ri_font->fontheight,
@@ -378,16 +381,6 @@ mgx_attach(device_t parent, device_t sel
 	fb->fb_type.fb_cmsize = 256;
 	fb->fb_type.fb_size = sc->sc_fbsize;
 	fb_attach(&sc->sc_fb, isconsole);
-
-#if 0
-	{
-		uint32_t ap;
-		/* reads 0xfd210000 */
-		mgx_write_4(sc, ATR_APERTURE, 0x00000000); 
-		ap = mgx_read_4(sc, ATR_APERTURE);
-		printf("aperture: %08x\n", ap);
-	}
-#endif
 }
 
 static void
@@ -514,7 +507,7 @@ mgx_wait_host(struct mgx_softc *sc)
 	return i;
 }
 
-static int
+/*static inline*/ int
 mgx_wait_fifo(struct mgx_softc *sc, unsigned int nfifo)
 {
 	unsigned int i;
@@ -580,7 +573,7 @@ mgx_setup(struct mgx_softc *sc, int dept
 	sc->sc_stride = sc->sc_width * (depth >> 3);
 	stride = sc->sc_stride >> 3;
 #ifdef MGX_DEBUG
-	sc->sc_height = 600;
+	sc->sc_height -= 150;
 #endif
 
 	sc->sc_depth = depth;
@@ -628,24 +621,7 @@ mgx_setup(struct mgx_softc *sc, int dept
 	mgx_write_1(sc, ATR_CURSOR_ENABLE, 0);
 	sc->sc_cursor = (uint8_t *)sc->sc_fbaddr + sc->sc_fbsize - 1024;
 	memset(sc->sc_cursor, 0xf0, 1024);
-
-#ifdef MGX_DEBUG
-	int j;
-	mgx_write_vga(sc, SEQ_INDEX, 0x10);
-	mgx_write_vga(sc, SEQ_DATA, 0x12);
-	for (i = 0x10; i < 0x30; i += 16) {
-		printf("%02x:", i);
-		for (j = 0; j < 16; j++) {
-			mgx_write_vga(sc, SEQ_INDEX, i + j);
-			printf(" %02x", mgx_read_vga(sc, SEQ_DATA));
-		}
-		printf("\n");
-	}
-#if 0
-	mgx_write_vga(sc, SEQ_INDEX, 0x1a);
-	mgx_write_vga(sc, SEQ_DATA, 0x0f);
-#endif
-#endif
+	memset(sc->sc_in, 0, sizeof(sc->sc_in));
 }
 
 static void
@@ -751,9 +727,9 @@ mgx_putchar_mono(void *cookie, int row, 
 	struct wsdisplay_font *font = PICK_FONT(ri, c);
 	struct vcons_screen *scr = ri->ri_hw;
 	struct mgx_softc *sc = scr->scr_cookie;
-	void *s, *d;
-	uint32_t fg, bg, scratch = (sc->sc_stride * sc->sc_height + 7) & ~7;
-	int x, y, wi, he;
+	uint8_t *s, *d;
+	uint32_t fg, bg, scratch = ((sc->sc_stride * sc->sc_height) + 7) & ~7;
+	int x, y, wi, he, len, i;
 
 	wi = font->fontwidth;
 	he = font->fontheight;
@@ -764,6 +740,12 @@ mgx_putchar_mono(void *cookie, int row, 
 	x = ri->ri_xorigin + col * wi;
 	y = ri->ri_yorigin + row * he;
 
+	if (!CHAR_IN_FONT(c, font)) {
+		c = 0x20;
+#ifdef MGX_DEBUG
+		bg = WSCOL_LIGHT_BLUE;
+#endif
+	}
 	if (c == 0x20) {
 		mgx_rectfill(sc, x, y, wi, he, bg);
 		if (attr & 1)
@@ -771,35 +753,42 @@ mgx_putchar_mono(void *cookie, int row, 
 		return;
 	}
 
+	mgx_wait_fifo(sc, 3);
+	mgx_write_4(sc, ATR_FG, ri->ri_devcmap[fg]);
+	mgx_write_4(sc, ATR_BG, ri->ri_devcmap[bg]);
+	mgx_write_1(sc, ATR_ROP, ROP_SRC);
+
 	/*
 	 * do hardware colour expansion
-	 * there has to be an upload port somewhere, sinde there are host blit
+	 * there has to be an upload port somewhere, since there are host blit
 	 * commands, but it's not used or mentioned in the xf86-video-apm driver
 	 * so for now we use the vram-to-vram blits to draw characters.
-	 * Use rotating buffers since commands can be queued and just because
-	 * the blitter can accept another command that does not mean that the
-	 * previous command(s) have finished, so make sure we don't touch the
-	 * buffers used for the last few operations
-	 * Align everything to 64bit, one for memcpy and also for the chip -
-	 * I'm not sure what the exact alignment requirements are but mono
-	 * bitmaps need at least 16bit.
+	 * stash most of the font in vram for speed, also:
+	 * - the sbus-pci bridge doesn't seem to support 64bit accesses,
+	 *   they will cause occasional data corruption and all sorts of weird
+	 *   side effects, so copy font bitmaps byte-wise
+	 * - at least it doesn't seem to need any kind of buffer flushing
+	 * - still use rotation buffers for characters that don't fall into the
+	 *   8 bit range
 	 */
-	sc->sc_buf = (sc->sc_buf + 1) & 3; /* rotate through 4 buffers */
-	scratch += sc->sc_buf * ((ri->ri_fontscale + 7) & ~7);
+
+	len = (ri->ri_fontscale + 7) & ~7;
 	s = WSFONT_GLYPH(c, font);
-	d = (uint8_t *)sc->sc_fbaddr + scratch;
-	memcpy(d, s, ri->ri_fontscale);
-	/*
-	 * try to make sure the glyph made it into vram before kicking the
-	 * blitter
-	 */
-	membar_sync();
-	volatile uint32_t junk = *(volatile uint32_t *)sc->sc_fbaddr;
-	__USE(junk);
-	mgx_wait_fifo(sc, 3);
-	mgx_write_4(sc, ATR_FG, ri->ri_devcmap[fg]);
-	mgx_write_4(sc, ATR_BG, ri->ri_devcmap[bg]);
-	mgx_write_1(sc, ATR_ROP, ROP_SRC);
+	if ((c > 32) && (c < 256)) {
+		scratch += len * c;
+		if (sc->sc_in[c] == 0) {
+			d = (uint8_t *)sc->sc_fbaddr + scratch;
+			for (i = 0; i < ri->ri_fontscale; i++)
+				d[i] = s[i];
+			sc->sc_in[c] = 1;
+		}
+	} else {
+		sc->sc_buf = (sc->sc_buf + 1) & 7; /* rotate through 8 buffers */
+		scratch += sc->sc_buf * len;
+		d = (uint8_t *)sc->sc_fbaddr + scratch;
+		for (i = 0; i < ri->ri_fontscale; i++)
+			d[i] = s[i];
+	}
 	mgx_wait_fifo(sc, 5);
 	mgx_write_4(sc, ATR_DEC, sc->sc_dec | (DEC_COMMAND_BLT << DEC_COMMAND_SHIFT) |
 	       (DEC_START_DIMX << DEC_START_SHIFT) |
@@ -913,6 +902,14 @@ mgx_eraserows(void *cookie, int row, int
 }
 
 static void
+mgx_adapt(struct vcons_screen *scr, void *cookie)
+{
+	struct mgx_softc *sc = cookie;
+	memset(sc->sc_in, 0, sizeof(sc->sc_in));
+	glyphcache_adapt(scr, &sc->sc_gc);
+}
+
+static void
 mgx_init_screen(void *cookie, struct vcons_screen *scr,
     int existing, long *defattr)
 {
@@ -950,7 +947,7 @@ mgx_init_screen(void *cookie, struct vco
 		    ri->ri_width / ri->ri_font->fontwidth);
 
 	ri->ri_hw = scr;
-
+	
 #ifdef MGX_NOACCEL
 if (0)
 #endif

Reply via email to