Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci a very preliminary driver for Wildcat 5110 / Sun...



details:   https://anonhg.NetBSD.org/src/rev/fc753bd6d67a
branches:  trunk
changeset: 752401:fc753bd6d67a
user:      macallan <macallan%NetBSD.org@localhost>
date:      Thu Feb 25 03:33:09 2010 +0000

description:
a very preliminary driver for Wildcat 5110 / Sun XVR-500 graphics boards
Since we don't have any documentationthis driver is unaccelerated and thanks
to the insane state we get the hardware in it's also slow and scrolling
looks weird.
Some hardware info came from OpenBSD's ifb driver.

diffstat:

 sys/dev/pci/files.pci |    8 +-
 sys/dev/pci/wcfb.c    |  484 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 491 insertions(+), 1 deletions(-)

diffs (truncated from 507 to 300 lines):

diff -r fa56eb442bc9 -r fc753bd6d67a sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci     Thu Feb 25 03:20:02 2010 +0000
+++ b/sys/dev/pci/files.pci     Thu Feb 25 03:33:09 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.pci,v 1.325 2010/02/22 05:55:10 ahoka Exp $
+#      $NetBSD: files.pci,v 1.326 2010/02/25 03:33:09 macallan Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -999,3 +999,9 @@
 attach pm2fb at pci
 file   dev/pci/pm2fb.c         pm2fb
 defflag        opt_pm2fb.h     PM2FB_DEBUG
+
+# 3Dlabs Wildcat / Sun XVR-500, 1200, Expert3D etc.
+device         wcfb: wsemuldisplaydev, rasops8, vcons
+attach         wcfb at pci
+file           dev/pci/wcfb.c  wcfb
+defflag                opt_wcfb.h      WCFB_DEBUG
diff -r fa56eb442bc9 -r fc753bd6d67a sys/dev/pci/wcfb.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/wcfb.c        Thu Feb 25 03:33:09 2010 +0000
@@ -0,0 +1,484 @@
+/*     $NetBSD: wcfb.c,v 1.1 2010/02/25 03:33:09 macallan Exp $ */
+
+/*-
+ * Copyright (c) 2007 Michael Lorenz
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: wcfb.c,v 1.1 2010/02/25 03:33:09 macallan Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/proc.h>
+#include <sys/mutex.h>
+#include <sys/ioctl.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/kauth.h>
+
+#include <dev/pci/pcidevs.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pciio.h>
+
+#include <dev/wscons/wsdisplayvar.h>
+#include <dev/wscons/wsconsio.h>
+#include <dev/wsfont/wsfont.h>
+#include <dev/rasops/rasops.h>
+#include <dev/wscons/wsdisplay_vconsvar.h>
+
+#include "opt_wsfb.h"
+#include "opt_wcfb.h"
+
+#ifdef WCFB_DEBUG
+# define DPRINTF printf
+#else
+# define DPRINTF while (0) printf
+#endif
+
+static int     wcfb_match(device_t, cfdata_t, void *);
+static void    wcfb_attach(device_t, device_t, void *);
+static int     wcfb_ioctl(void *, void *, u_long, void *, int,
+                   struct lwp *);
+static paddr_t wcfb_mmap(void *, void *, off_t, int);
+
+struct wcfb_softc {
+       device_t sc_dev;
+
+       pci_chipset_tag_t sc_pc;
+       pcitag_t sc_pcitag;
+
+       bus_space_tag_t sc_memt;
+       bus_space_tag_t sc_regt, sc_wtft;
+       bus_space_tag_t sc_iot;
+
+       bus_space_handle_t sc_fbh, sc_wtfh;
+       bus_space_handle_t sc_regh;
+       bus_addr_t sc_fb, sc_reg, sc_wtf;
+       bus_size_t sc_fbsize, sc_regsize, sc_wtfsize;
+
+       int sc_width, sc_height, sc_stride;
+       int sc_locked;
+       uint8_t *sc_fbaddr;
+       struct vcons_screen sc_console_screen;
+       struct wsscreen_descr sc_defaultscreen_descr;
+       const struct wsscreen_descr *sc_screens[1];
+       struct wsscreen_list sc_screenlist;
+       struct vcons_data vd;
+       int sc_mode;
+       u_char sc_cmap_red[256];
+       u_char sc_cmap_green[256];
+       u_char sc_cmap_blue[256];
+       uint32_t sc_fb0off;
+
+       void (*copycols)(void *, int, int, int, int);
+       void (*erasecols)(void *, int, int, int, long);
+       void (*copyrows)(void *, int, int, int);
+       void (*eraserows)(void *, int, int, long);
+       void (*putchar)(void *, int, int, u_int, long);
+       void (*cursor)(void *, int, int, int);
+       
+};
+
+static void    wcfb_init_screen(void *, struct vcons_screen *, int, long *);
+
+CFATTACH_DECL_NEW(wcfb, sizeof(struct wcfb_softc),
+    wcfb_match, wcfb_attach, NULL, NULL);
+
+struct wsdisplay_accessops wcfb_accessops = {
+       wcfb_ioctl,
+       wcfb_mmap,
+       NULL,   /* alloc_screen */
+       NULL,   /* free_screen */
+       NULL,   /* show_screen */
+       NULL,   /* load_font */
+       NULL,   /* pollc */
+       NULL    /* scroll */
+};
+
+static void    wcfb_putchar(void *, int, int, u_int, long);
+static void    wcfb_cursor(void *, int, int, int);
+static void    wcfb_copycols(void *, int, int, int, int);
+static void    wcfb_erasecols(void *, int, int, int, long);
+static void    wcfb_copyrows(void *, int, int, int);
+static void    wcfb_eraserows(void *, int, int, long);
+
+static void    wcfb_putpalreg(struct wcfb_softc *, int, int, int, int);
+
+static int
+wcfb_match(device_t parent, cfdata_t match, void *aux)
+{
+       struct pci_attach_args *pa = aux;
+
+       if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_3DLABS &&
+           PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_3DLABS_WILDCAT5110)
+               return 100;
+
+       return 0;
+}
+
+static void
+wcfb_attach(device_t parent, device_t self, void *aux)
+{
+       struct wcfb_softc *sc = device_private(self);
+       struct pci_attach_args *pa = aux;
+       struct rasops_info      *ri;
+       prop_dictionary_t       dict;
+       struct wsemuldisplaydev_attach_args aa;
+       int                     i, j;
+       unsigned long           defattr;
+       bool                    is_console;
+       char                    devinfo[256];
+       void *wtf;
+       uint32_t *tcfb;
+
+       sc->sc_dev = self;
+       sc->putchar = NULL;
+       pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
+       aprint_naive("\n");
+       aprint_normal(": %s\n", devinfo);
+
+       dict = device_properties(self);
+       prop_dictionary_get_bool(dict, "is_console", &is_console);
+if(!is_console) return;
+
+       sc->sc_memt = pa->pa_memt;
+       sc->sc_iot = pa->pa_iot;        
+       sc->sc_pc = pa->pa_pc;
+       sc->sc_pcitag = pa->pa_tag;
+
+       /* fill in parameters from properties */
+       if (!prop_dictionary_get_uint32(dict, "width", &sc->sc_width)) {
+               aprint_error("%s: no width property\n", device_xname(self));
+               return;
+       }
+       if (!prop_dictionary_get_uint32(dict, "height", &sc->sc_height)) {
+               aprint_error("%s: no height property\n", device_xname(self));
+               return;
+       }
+
+       if (pci_mapreg_map(pa, 0x14, PCI_MAPREG_TYPE_MEM, 0,
+           &sc->sc_regt, &sc->sc_regh, &sc->sc_reg, &sc->sc_regsize)) {
+               aprint_error("%s: failed to map registers.\n",
+                   device_xname(sc->sc_dev));
+       }
+
+       if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM, BUS_SPACE_MAP_LINEAR,
+           &sc->sc_memt, &sc->sc_fbh, &sc->sc_fb, &sc->sc_fbsize)) {
+               aprint_error("%s: failed to map framebuffer.\n",
+                   device_xname(sc->sc_dev));
+       }
+
+       if (pci_mapreg_map(pa, 0x18, PCI_MAPREG_TYPE_MEM, BUS_SPACE_MAP_LINEAR,
+           &sc->sc_wtft, &sc->sc_wtfh, &sc->sc_wtf, &sc->sc_wtfsize)) {
+               aprint_error("%s: failed to map wtf.\n",
+                   device_xname(sc->sc_dev));
+       }
+       wtf = bus_space_vaddr(sc->sc_wtft, sc->sc_wtfh);
+       memset(wtf, 0, 0x100000);
+
+       sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
+
+       sc->sc_fb0off = bus_space_read_4(sc->sc_regt, sc->sc_regh, 0x8080) -
+           sc->sc_fb;
+       sc->sc_stride = 1 << 
+           ((bus_space_read_4(sc->sc_regt, sc->sc_regh, 0x8074) & 0x00ff0000) >> 16);
+       printf("%s: %d x %d, %d\n", device_xname(sc->sc_dev), 
+           sc->sc_width, sc->sc_height, sc->sc_stride);
+       for (i = 0x40; i < 0x100; i += 16) {
+               printf("%04x:", i);
+               for (j = 0; j < 16; j += 4) {
+                       printf(" %08x", bus_space_read_4(sc->sc_regt,
+                           sc->sc_regh, 0x8000 + i + j));
+               }
+               printf("\n");
+       }
+
+       sc->sc_defaultscreen_descr = (struct wsscreen_descr){
+               "default",
+               0, 0,
+               NULL,
+               8, 16,
+               WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
+               NULL
+       };
+       sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
+       sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
+       sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
+       sc->sc_locked = 0;
+
+       vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
+           &wcfb_accessops);
+       sc->vd.init_screen = wcfb_init_screen;
+
+       /* init engine here */
+#if 0
+       wcfb_init(sc);
+#endif
+
+       ri = &sc->sc_console_screen.scr_ri;
+
+       j = 0;
+       for (i = 0; i < 256; i++) {
+
+               sc->sc_cmap_red[i] = rasops_cmap[j];
+               sc->sc_cmap_green[i] = rasops_cmap[j + 1];
+               sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
+               wcfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
+                   rasops_cmap[j + 2]);
+               j += 3;
+       }
+       wcfb_putpalreg(sc, 0, 0, 0, 0);
+       wcfb_putpalreg(sc, 15, 0xff, 0xff, 0xff);
+
+       if (is_console) {
+               vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
+                   &defattr);
+               sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
+
+#if 0
+               wcfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
+                   ri->ri_devcmap[(defattr >> 16) & 0xff]);
+#else
+               /*memset(sc->sc_fbaddr + sc->sc_fb0off, 0, 0x400000);*/
+#endif
+               sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
+               sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
+               sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
+               sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
+               wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
+                   defattr);
+               vcons_replay_msgbuf(&sc->sc_console_screen);
+       } else {
+               /*



Home | Main Index | Thread Index | Old Index