Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci Bugfixes and acceleration support.



details:   https://anonhg.NetBSD.org/src/rev/9905cd6f3401
branches:  trunk
changeset: 572638:9905cd6f3401
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Jan 09 16:29:20 2005 +0000

description:
Bugfixes and acceleration support.
>From Michael Lorenz.

diffstat:

 sys/dev/pci/machfb.c |  348 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 324 insertions(+), 24 deletions(-)

diffs (truncated from 527 to 300 lines):

diff -r 0d8268a15026 -r 9905cd6f3401 sys/dev/pci/machfb.c
--- a/sys/dev/pci/machfb.c      Sun Jan 09 16:03:45 2005 +0000
+++ b/sys/dev/pci/machfb.c      Sun Jan 09 16:29:20 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machfb.c,v 1.18 2004/04/23 21:13:06 itojun Exp $       */
+/*     $NetBSD: machfb.c,v 1.19 2005/01/09 16:29:20 martin Exp $       */
 
 /*
  * Copyright (c) 2002 Bang Jun-Young
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machfb.c,v 1.18 2004/04/23 21:13:06 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machfb.c,v 1.19 2005/01/09 16:29:20 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -58,6 +58,8 @@
 #include <dev/wsfont/wsfont.h>
 #include <dev/rasops/rasops.h>
 
+#include "opt_wsemul.h"
+
 #define MACH64_REG_SIZE                1024
 #define MACH64_REG_OFF         0x7ffc00
 
@@ -119,6 +121,10 @@
        struct callout switch_callout;
        LIST_HEAD(, mach64screen) screens;
        const struct wsscreen_descr *currenttype;
+       u_char sc_cmap_red[256];
+       u_char sc_cmap_green[256];
+       u_char sc_cmap_blue[256];       
+       int sc_dacw;
 };
 
 struct mach64screen {
@@ -205,6 +211,8 @@
          VID_NHSYNC | VID_NVSYNC }
 };
 
+/* Macallan: let the terminal emulator program the palette, it should be in the softc anyway */
+#if 1
 /* FIXME values are wrong! */
 const u_char mach64_cmap[16 * 3] = {
        0x00, 0x00, 0x00, /* black */
@@ -214,7 +222,7 @@
        0x00, 0x00, 0x7f, /* blue */
        0x7f, 0x00, 0x7f, /* magenta */
        0x00, 0x7f, 0x7f, /* cyan */
-       0xff, 0xff, 0xff, /* white */
+       0xc8, 0xc8, 0xc8, /* white */
 
        0x7f, 0x7f, 0x7f, /* black */
        0xff, 0x00, 0x00, /* red */
@@ -225,6 +233,11 @@
        0x00, 0xff, 0xff, /* cyan */
        0xff, 0xff, 0xff, /* white */
 };
+#endif
+
+#ifdef WSEMUL_VT100
+extern const u_char rasops_cmap[768];
+#endif
 
 int    mach64_match(struct device *, struct cfdata *, void *);
 void   mach64_attach(struct device *, struct device *, void *);
@@ -264,6 +277,15 @@
 void   mach64_eraserows(void *, int, int, long);
 int    mach64_allocattr(void *, int, int, int, long *);
 
+void   mach64_scroll(void *, void *, int);
+
+int mach64_putcmap(struct mach64_softc *, struct wsdisplay_cmap *);
+int mach64_getcmap(struct mach64_softc *, struct wsdisplay_cmap *);
+int mach64_putpalreg(struct mach64_softc *, uint8_t, uint8_t, uint8_t, uint8_t);
+void mach64_bitblt(struct mach64_softc *, int, int, int, int, int, int, int, int) ;
+void mach64_rectfill(struct mach64_softc *, int, int, int, int, int);
+void mach64_showpal(struct mach64_softc *);
+
 #if 0
 const struct wsdisplay_emulops mach64_emulops = {
        mach64_cursor,
@@ -366,7 +388,13 @@
        mach64_alloc_screen,
        mach64_free_screen,
        mach64_show_screen,
-       NULL
+       NULL,   /* load_font */
+       NULL,   /* polls */
+       NULL,   /* getwschar */
+       NULL,   /* putwschar */
+       NULL,   /* scroll */
+       NULL,   /* getborder */
+       NULL    /* setborder */
 };
 
 /*
@@ -397,6 +425,7 @@
 {
 
        bus_space_write_4(sc->sc_regt, sc->sc_regh, index, data);
+       bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 4, BUS_SPACE_BARRIER_WRITE);
 }
 
 static inline void
@@ -404,6 +433,7 @@
 {
 
        bus_space_write_1(sc->sc_regt, sc->sc_regh, index, data);
+       bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 1, BUS_SPACE_BARRIER_WRITE);
 }
 
 static inline void
@@ -465,7 +495,7 @@
 
        sc->sc_pc = pa->pa_pc;
        sc->sc_pcitag = pa->pa_tag;
-
+       sc->sc_dacw=-1;
        pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
        printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
 
@@ -570,27 +600,49 @@
        mach64_console_screen.ri.ri_width = default_mode.hdisplay;
        mach64_console_screen.ri.ri_height = default_mode.vdisplay;
        mach64_console_screen.ri.ri_stride = mach64_console_screen.ri.ri_width;
-       mach64_console_screen.ri.ri_flg = RI_CLEAR;
+
+       mach64_console_screen.ri.ri_flg = RI_CLEAR|RI_CENTER;
+
+#ifdef WSEMUL_SUN
+       mach64_console_screen.ri.ri_flg = RI_CLEAR|RI_CENTER|RI_FORCEMONO;
+#endif
 
        rasops_init(&mach64_console_screen.ri, mach64_console_screen.ri.ri_height / 16,
-           mach64_console_screen.ri.ri_width / 8);
+           mach64_console_screen.ri.ri_width / 8);     /* XXX width/height are nonsense */
+       
+       /* enable acceleration */
+       mach64_console_screen.ri.ri_ops.copyrows=mach64_copyrows;
+       mach64_console_screen.ri.ri_ops.eraserows=mach64_eraserows;
+       mach64_console_screen.ri.ri_ops.copycols=mach64_copycols;
+       mach64_console_screen.ri.ri_ops.erasecols=mach64_erasecols;
 
        mach64_defaultscreen.nrows = mach64_console_screen.ri.ri_rows;
        mach64_defaultscreen.ncols = mach64_console_screen.ri.ri_cols;
 
        mach64_console_screen.ri.ri_ops.allocattr(&mach64_console_screen.ri, 0, 0, 0,
            &defattr);
-
+               
+       /* really necessary? */
+       mach64_defaultscreen.capabilities=mach64_console_screen.ri.ri_caps;
+       mach64_defaultscreen.textops=&mach64_console_screen.ri.ri_ops;
+       
        /* Initialize fonts */
+       /* XXX Macallan: shouldn't that happen /before/ we call rasops_init()? */
        wsfont_init();
-
+       
        if (console) {
                mach64_init_screen(sc, &mach64_console_screen,
                    &mach64_defaultscreen, 1, &defattr, setmode);
                wsdisplay_cnattach(&mach64_defaultscreen, &mach64_console_screen.ri, 
                    0, 0, defattr);
        }
+       
+       mach64_init_lut(sc);
 
+#ifdef DEBUG
+       mach64_showpal(sc);
+       delay(4000000);
+#endif
        aa.console = console;
        aa.scrdata = &mach64_screenlist;
        aa.accessops = &mach64_accessops;
@@ -902,7 +954,9 @@
        case 8:
                regw(sc, DP_PIX_WIDTH, HOST_8BPP | SRC_8BPP | DST_8BPP);
                regw(sc, DP_CHAIN_MASK, DP_CHAIN_8BPP);
-               regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) & ~DAC_8BIT_EN);
+               /* XXX Macallan: huh? We /want/ an 8 bit per channel palette! */
+               /*regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) & ~DAC_8BIT_EN);*/
+               regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
                break;
 #if 0
        case 32:
@@ -1060,15 +1114,103 @@
 void
 mach64_init_lut(struct mach64_softc *sc)
 {
-       int i;
+       /* XXX this is pretty dodgy since it's perfectly possible that
+          both terminal emulations are compiled into the kernel, in this
+          case we'd install the VT100 colour map which may be wrong */
+#ifdef WSEMUL_SUN
+       mach64_putpalreg(sc,0,255,255,255);
+       mach64_putpalreg(sc,1,0,0,0);
+       mach64_putpalreg(sc,255,0,0,0);
+#endif
+#ifdef WSEMUL_VT100
+       {
+               int i,idx;
+               idx=0;
+               for(i=0;i<256;i++) {
+                       mach64_putpalreg(sc,i,rasops_cmap[idx],rasops_cmap[idx+1],rasops_cmap[idx+2]);
+                       idx+=3;
+               }
+       }
+#endif
+}
 
-       regwb(sc, DAC_REGS, 0);
+int mach64_putpalreg(struct mach64_softc *sc, uint8_t index, uint8_t r, uint8_t g, uint8_t b)
+{
+       sc->sc_cmap_red[index]=r;
+       sc->sc_cmap_green[index]=g;
+       sc->sc_cmap_blue[index]=b;
+       /* writing the dac index takes a while, in theory we can poll some register
+          to see when it's ready - but we better avoid writing it unnecessarily */
+       if(index!=sc->sc_dacw)
+       {
+               regwb(sc, DAC_MASK, 0xff);
+               regwb(sc, DAC_WINDEX, index);
+       }
+       sc->sc_dacw=index+1;
+       regwb(sc, DAC_DATA, r);
+       regwb(sc, DAC_DATA, g);
+       regwb(sc, DAC_DATA, b);
+       return 0;
+}
+
+int mach64_putcmap(struct mach64_softc *sc, struct wsdisplay_cmap *cm)
+{
+       u_int index = cm->index;
+       u_int count = cm->count;
+       int i, error;
+       u_char rbuf[256], gbuf[256], bbuf[256];
+       u_char *r, *g, *b;
 
-       for (i = 0; i < 16; i++) {
-               regwb(sc, DAC_REGS + 1, mach64_cmap[i * 3]);
-               regwb(sc, DAC_REGS + 1, mach64_cmap[i * 3 + 1]);
-               regwb(sc, DAC_REGS + 1, mach64_cmap[i + 3 + 2]);
+       printf("putcmap: %d %d\n",index, count);
+       if (cm->index >= 256 || cm->count > 256 ||
+           (cm->index + cm->count) > 256)
+               return EINVAL;
+       error = copyin(cm->red, &rbuf[index], count);
+       if (error)
+               return error;
+       error = copyin(cm->green, &gbuf[index], count);
+       if (error)
+               return error;
+       error = copyin(cm->blue, &bbuf[index], count);
+       if (error)
+               return error;
+
+       memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
+       memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
+       memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
+
+       r = &sc->sc_cmap_red[index];
+       g = &sc->sc_cmap_green[index];
+       b = &sc->sc_cmap_blue[index];
+       
+       for (i = 0; i < count; i++) {
+               mach64_putpalreg(sc,index,*r, *g, *b);
+               index++;
+               r++, g++, b++;
        }
+       return 0;
+}
+
+int mach64_getcmap(struct mach64_softc *sc, struct wsdisplay_cmap *cm)
+{
+       u_int index = cm->index;
+       u_int count = cm->count;
+       int error;
+
+       if (index >= 255 || count > 256 || index + count > 256)
+               return EINVAL;
+       
+       error = copyout(&sc->sc_cmap_red[index],   cm->red,   count);
+       if (error)
+               return error;
+       error = copyout(&sc->sc_cmap_green[index], cm->green, count);
+       if (error)
+               return error;
+       error = copyout(&sc->sc_cmap_blue[index],  cm->blue,  count);
+       if (error)
+               return error;
+
+       return 0;
 }
 
 void
@@ -1097,8 +1239,9 @@



Home | Main Index | Thread Index | Old Index