- store bitmap fonts in vram

- don't try to force buffer flushes
- avoid 64bit writes to vram
-> no more corruption of font bitmaps
This commit is contained in:
macallan 2017-08-04 23:54:46 +00:00
parent 521cb9d122
commit ed20f135c9
1 changed files with 65 additions and 68 deletions

View File

@ -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 *, struct wsdisplay_cmap *);
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, int, int, int);
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 self, void *args)
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 self, void *args)
}
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 self, void *args)
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 self, void *args)
* 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 self, void *args)
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 depth)
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 depth)
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, int col, u_int c, long attr)
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, int col, u_int c, long attr)
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, int col, u_int c, long attr)
return;
}
/*
* do hardware colour expansion
* there has to be an upload port somewhere, sinde 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.
*/
sc->sc_buf = (sc->sc_buf + 1) & 3; /* rotate through 4 buffers */
scratch += sc->sc_buf * ((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);
/*
* do hardware colour expansion
* 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.
* 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
*/
len = (ri->ri_fontscale + 7) & ~7;
s = WSFONT_GLYPH(c, font);
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) |
@ -912,6 +901,14 @@ mgx_eraserows(void *cookie, int row, int nrows, long fillattr)
mgx_rectfill(sc, x, y, width, height, bg);
}
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 vcons_screen *scr,
ri->ri_width / ri->ri_font->fontwidth);
ri->ri_hw = scr;
#ifdef MGX_NOACCEL
if (0)
#endif