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 driver for the Permedia 2 graphics processor, ...



details:   https://anonhg.NetBSD.org/src/rev/6131c51e161a
branches:  trunk
changeset: 748579:6131c51e161a
user:      macallan <macallan%NetBSD.org@localhost>
date:      Wed Oct 28 02:10:27 2009 +0000

description:
A driver for the Permedia 2 graphics processor, so far it's been tested only
on sparc64 with a Sun PGX32 / TechSource Raptor GFX 8P
So far it accelerates block copies, rectangle fills and the cursor, it
supports the usual wsdisplay / vcons stuff.
TODO:
- character drawing by hardware so we don't need to map the framebuffer
- DDC2 support
- mode setting
This driver still relies on the firmware to set up graphics modes etc. so it
won't work on x86 ( or non-OpenFirmware for that matter ) unless you use the
VESA BIOS to set up graphics and pass the right properties ( width, height
etc. ) to the driver. For the same reason it will work only if it's the
OpenFirmware console.

diffstat:

 sys/dev/pci/files.pci |    8 +-
 sys/dev/pci/pm2fb.c   |  759 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/pci/pm2reg.h  |  133 ++++++++
 3 files changed, 899 insertions(+), 1 deletions(-)

diffs (truncated from 919 to 300 lines):

diff -r 85a93446e14c -r 6131c51e161a sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci     Tue Oct 27 23:23:33 2009 +0000
+++ b/sys/dev/pci/files.pci     Wed Oct 28 02:10:27 2009 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.pci,v 1.322 2009/09/26 19:43:04 snj Exp $
+#      $NetBSD: files.pci,v 1.323 2009/10/28 02:10:27 macallan Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -988,3 +988,9 @@
 
 # High Definition Audio
 include "dev/pci/hdaudio/files.hdaudio"
+
+# Permedia 2 / Sun PGX32 / Raptor
+device pm2fb: wsemuldisplaydev, rasops8, vcons, videomode, iic, i2c_bitbang
+attach pm2fb at pci
+file   dev/pci/pm2fb.c         pm2fb
+defflag        opt_pm2fb.h     PM2FB_DEBUG
diff -r 85a93446e14c -r 6131c51e161a sys/dev/pci/pm2fb.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/pm2fb.c       Wed Oct 28 02:10:27 2009 +0000
@@ -0,0 +1,759 @@
+/*     $NetBSD: pm2fb.c,v 1.1 2009/10/28 02:10:27 macallan Exp $       */
+
+/*
+ * Copyright (c) 2009 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 AUTHOR ``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 AUTHOR 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.
+ */
+
+/*
+ * A console driver for Permedia 2 graphics controllers
+ * tested on sparc64 only so far
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: pm2fb.c,v 1.1 2009/10/28 02:10:27 macallan Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+#include <sys/lwp.h>
+#include <sys/kauth.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <dev/videomode/videomode.h>
+
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcidevs.h>
+#include <dev/pci/pciio.h>
+#include <dev/pci/pm2reg.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 <dev/i2c/i2cvar.h>
+
+struct pm2fb_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_iot;
+
+       bus_space_handle_t sc_fbh;
+       bus_space_handle_t sc_regh;
+       bus_addr_t sc_fb, sc_reg;
+       bus_size_t sc_fbsize, sc_regsize;
+
+       int sc_width, sc_height, sc_depth, sc_stride;
+       int sc_locked;
+       void *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];
+       /* engine stuff */
+       uint32_t sc_master_cntl;
+};
+
+static int     pm2fb_match(device_t, cfdata_t, void *);
+static void    pm2fb_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(pm2fb, sizeof(struct pm2fb_softc),
+    pm2fb_match, pm2fb_attach, NULL, NULL);
+
+extern const u_char rasops_cmap[768];
+
+static int     pm2fb_ioctl(void *, void *, u_long, void *, int,
+                            struct lwp *);
+static paddr_t pm2fb_mmap(void *, void *, off_t, int);
+static void    pm2fb_init_screen(void *, struct vcons_screen *, int, long *);
+
+static int     pm2fb_putcmap(struct pm2fb_softc *, struct wsdisplay_cmap *);
+static int     pm2fb_getcmap(struct pm2fb_softc *, struct wsdisplay_cmap *);
+static void    pm2fb_restore_palette(struct pm2fb_softc *);
+static int     pm2fb_putpalreg(struct pm2fb_softc *, uint8_t, uint8_t,
+                           uint8_t, uint8_t);
+
+static void    pm2fb_init(struct pm2fb_softc *);
+static void    pm2fb_flush_engine(struct pm2fb_softc *);
+static void    pm2fb_rectfill(struct pm2fb_softc *, int, int, int, int,
+                           uint32_t);
+static void    pm2fb_bitblt(struct pm2fb_softc *, int, int, int, int, int,
+                           int, int);
+
+static void    pm2fb_cursor(void *, int, int, int);
+#if 0
+static void    pm2fb_putchar(void *, int, int, u_int, long);
+#endif
+static void    pm2fb_copycols(void *, int, int, int, int);
+static void    pm2fb_erasecols(void *, int, int, int, long);
+static void    pm2fb_copyrows(void *, int, int, int);
+static void    pm2fb_eraserows(void *, int, int, long);
+
+struct wsdisplay_accessops pm2fb_accessops = {
+       pm2fb_ioctl,
+       pm2fb_mmap,
+       NULL,   /* alloc_screen */
+       NULL,   /* free_screen */
+       NULL,   /* show_screen */
+       NULL,   /* load_font */
+       NULL,   /* pollc */
+       NULL    /* scroll */
+};
+
+static inline void
+pm2fb_wait(struct pm2fb_softc *sc, int slots)
+{
+       uint32_t reg;
+
+       do {
+               reg = bus_space_read_4(sc->sc_memt, sc->sc_regh, 
+                       PM2_INPUT_FIFO_SPACE);
+       } while (reg <= slots);
+}
+
+static void
+pm2fb_flush_engine(struct pm2fb_softc *sc)
+{
+
+       pm2fb_wait(sc, 2);
+
+       bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_FILTER_MODE,
+           PM2FLT_PASS_SYNC);
+       bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_SYNC, 0);
+       do {
+               while (bus_space_read_4(sc->sc_memt, sc->sc_regh, 
+                       PM2_OUTPUT_FIFO_WORDS) == 0);
+       } while (bus_space_read_4(sc->sc_memt, sc->sc_regh, PM2_OUTPUT_FIFO) != 
+           0x188);
+}
+
+static int
+pm2fb_match(device_t parent, cfdata_t match, void *aux)
+{
+       struct pci_attach_args *pa = (struct pci_attach_args *)aux;
+
+       if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY)
+               return 0;
+       if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3DLABS)
+               return 0;
+
+       /* only cards tested on so far - likely need a list */
+       if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_3DLABS_PERMEDIA2) ||
+           (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_3DLABS_PERMEDIA2V))
+               return 100;
+       return (0);
+}
+
+static void
+pm2fb_attach(device_t parent, device_t self, void *aux)
+{
+       struct pm2fb_softc      *sc = device_private(self);
+       struct pci_attach_args  *pa = aux;
+       struct rasops_info      *ri;
+       char devinfo[256];
+       struct wsemuldisplaydev_attach_args aa;
+       prop_dictionary_t       dict;
+       unsigned long           defattr;
+       bool                    is_console;
+       int i, j;
+
+       sc->sc_pc = pa->pa_pc;
+       sc->sc_pcitag = pa->pa_tag;
+       sc->sc_memt = pa->pa_memt;
+       sc->sc_iot = pa->pa_iot;
+       sc->sc_dev = self;
+
+       pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
+       aprint_normal(": %s\n", devinfo);
+
+       /* fill in parameters from properties */
+       dict = device_properties(self);
+       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 (!prop_dictionary_get_uint32(dict, "depth", &sc->sc_depth)) {
+               aprint_error("%s: no depth property\n", device_xname(self));
+               return;
+       }
+       /*
+        * don't look at the linebytes property - The Raptor firmware lies
+        * about it. Get it from width * depth >> 3 instead.
+        */
+       sc->sc_stride = sc->sc_width * (sc->sc_depth >> 3);
+
+       prop_dictionary_get_bool(dict, "is_console", &is_console);
+
+       if (pci_mapreg_map(pa, 0x14, 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 the frame buffer.\n",
+                   device_xname(sc->sc_dev));
+       }
+       sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
+
+       if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM, 0,
+           &sc->sc_memt, &sc->sc_regh, &sc->sc_reg, &sc->sc_regsize)) {
+               aprint_error("%s: failed to map registers.\n",
+                   device_xname(sc->sc_dev));
+       }
+
+       /*
+        * XXX yeah, casting the fb address to uint32_t is formally wrong
+        * but as far as I know there are no PM2 with 64bit BARs
+        */
+       aprint_normal("%s: %d MB aperture at 0x%08x\n", device_xname(self),
+           (int)(sc->sc_fbsize >> 20), (uint32_t)sc->sc_fb);
+
+       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,
+           &pm2fb_accessops);
+       sc->vd.init_screen = pm2fb_init_screen;
+
+       /* init engine here */
+       pm2fb_init(sc);
+
+       ri = &sc->sc_console_screen.scr_ri;
+
+       j = 0;
+       for (i = 0; i < (1 << sc->sc_depth); 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];
+               pm2fb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
+                   rasops_cmap[j + 2]);
+               j += 3;



Home | Main Index | Thread Index | Old Index