Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc64/dev a simple fb driver for Sun XVR-1000 boards



details:   https://anonhg.NetBSD.org/src/rev/4534e2d5b86a
branches:  trunk
changeset: 750377:4534e2d5b86a
user:      macallan <macallan%NetBSD.org@localhost>
date:      Tue Dec 29 06:55:55 2009 +0000

description:
a simple fb driver for Sun XVR-1000 boards

diffstat:

 sys/arch/sparc64/dev/gfb.c |  437 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 437 insertions(+), 0 deletions(-)

diffs (truncated from 441 to 300 lines):

diff -r 35101012c32f -r 4534e2d5b86a sys/arch/sparc64/dev/gfb.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sparc64/dev/gfb.c        Tue Dec 29 06:55:55 2009 +0000
@@ -0,0 +1,437 @@
+/*     $NetBSD: gfb.c,v 1.1 2009/12/29 06:55:55 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 Sun XVR-1000 graphics cards
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: gfb.c,v 1.1 2009/12/29 06:55:55 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 <sys/kmem.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <dev/videomode/videomode.h>
+
+#include <machine/bus.h>
+#include <machine/autoconf.h>
+#include <machine/openfirm.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>
+
+
+struct gfb_softc {
+       device_t sc_dev;
+
+       bus_space_tag_t sc_memt;
+
+       bus_space_handle_t sc_fbh;
+       bus_addr_t sc_fb_paddr;
+
+       int sc_width, sc_height, sc_depth, sc_stride, sc_fblen;
+       int sc_locked;
+       void *sc_fbaddr, *sc_shadow;
+       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;
+       int sc_node;
+       u_char sc_cmap_red[256];
+       u_char sc_cmap_green[256];
+       u_char sc_cmap_blue[256];
+};
+
+static int     gfb_match(device_t, cfdata_t, void *);
+static void    gfb_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(gfb, sizeof(struct gfb_softc),
+    gfb_match, gfb_attach, NULL, NULL);
+
+extern const u_char rasops_cmap[768];
+
+static int     gfb_ioctl(void *, void *, u_long, void *, int,
+                            struct lwp *);
+static paddr_t gfb_mmap(void *, void *, off_t, int);
+static void    gfb_init_screen(void *, struct vcons_screen *, int, long *);
+
+static int     gfb_putcmap(struct gfb_softc *, struct wsdisplay_cmap *);
+static int     gfb_getcmap(struct gfb_softc *, struct wsdisplay_cmap *);
+static void    gfb_restore_palette(struct gfb_softc *);
+static int     gfb_putpalreg(struct gfb_softc *, uint8_t, uint8_t,
+                           uint8_t, uint8_t);
+
+struct wsdisplay_accessops gfb_accessops = {
+       gfb_ioctl,
+       gfb_mmap,
+       NULL,   /* alloc_screen */
+       NULL,   /* free_screen */
+       NULL,   /* show_screen */
+       NULL,   /* load_font */
+       NULL,   /* pollc */
+       NULL    /* scroll */
+};
+
+extern int prom_stdout_node;
+
+static int
+gfb_match(device_t parent, cfdata_t match, void *aux)
+{
+       struct mainbus_attach_args *ma = aux;
+
+       if (strcmp(ma->ma_name, "SUNW,gfb") == 0 )
+               return 100;
+       return 0;
+}
+
+static void
+gfb_attach(device_t parent, device_t self, void *aux)
+{
+       struct gfb_softc        *sc = device_private(self);
+       struct mainbus_attach_args      *ma = aux;
+       struct rasops_info      *ri;
+       struct wsemuldisplaydev_attach_args aa;
+       unsigned long           defattr;
+       bool                    is_console;
+       int i, j;
+
+       sc->sc_memt = ma->ma_bustag;
+       sc->sc_dev = self;
+       sc->sc_node = ma->ma_node;
+
+       if (ma->ma_nreg < 7) {
+               aprint_error("%s: can't find the fb range\n",
+                   device_xname(self));
+               return;
+       }
+
+       is_console = (prom_stdout_node == ma->ma_node);
+
+       aprint_normal(": Sun XVR-1000%s\n", is_console ? " (console)" : "");
+
+       sc->sc_depth = 32;
+       sc->sc_stride = 0x4000;
+       sc->sc_height = prom_getpropint(sc->sc_node, "height", 0);
+       sc->sc_width = prom_getpropint(sc->sc_node, "width", 0);
+       sc->sc_fblen = sc->sc_stride * sc->sc_height;
+
+       if (sc->sc_fblen == 0) {
+               aprint_error("%s: not set up by firmware, can't continue.\n",
+                   device_xname(self));
+               return;
+       }
+
+       sc->sc_shadow = kmem_alloc(sc->sc_fblen, KM_SLEEP);
+       sc->sc_locked = 0;
+       sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
+
+       if (bus_space_map(sc->sc_memt, ma->ma_reg[6].ur_paddr,
+           sc->sc_fblen, BUS_SPACE_MAP_LINEAR, &sc->sc_fbh)) {
+               printf(": failed to map the framebuffer\n");
+               return;
+       }
+       sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
+       sc->sc_fb_paddr = ma->ma_reg[6].ur_paddr;
+
+       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,
+           &gfb_accessops);
+       sc->vd.init_screen = gfb_init_screen;
+
+       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];
+               gfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
+                   rasops_cmap[j + 2]);
+               j += 3;
+       }
+
+       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 notyet
+               gfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
+                   ri->ri_devcmap[(defattr >> 16) & 0xff]);
+#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 {
+               /*
+                * since we're not the console we can postpone the rest
+                * until someone actually allocates a screen for us
+                */
+               (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
+       }
+
+       aa.console = is_console;
+       aa.scrdata = &sc->sc_screenlist;
+       aa.accessops = &gfb_accessops;
+       aa.accesscookie = &sc->vd;
+
+       config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
+}
+
+static int
+gfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
+       struct lwp *l)
+{
+       struct vcons_data *vd = v;
+       struct gfb_softc *sc = vd->cookie;
+       struct wsdisplay_fbinfo *wdf;
+       struct vcons_screen *ms = vd->active;
+
+       switch (cmd) {
+
+               case WSDISPLAYIO_GTYPE:
+                       *(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
+                       return 0;
+
+               case WSDISPLAYIO_GINFO:
+                       if (ms == NULL)
+                               return ENODEV;
+                       wdf = (void *)data;
+                       wdf->height = ms->scr_ri.ri_height;
+                       wdf->width = ms->scr_ri.ri_width;
+                       wdf->depth = ms->scr_ri.ri_depth;
+                       wdf->cmsize = 256;
+                       return 0;
+
+               case WSDISPLAYIO_GETCMAP:
+                       return gfb_getcmap(sc,
+                           (struct wsdisplay_cmap *)data);
+
+               case WSDISPLAYIO_PUTCMAP:
+                       return gfb_putcmap(sc,
+                           (struct wsdisplay_cmap *)data);
+
+               case WSDISPLAYIO_LINEBYTES:
+                       *(u_int *)data = sc->sc_stride;
+                       return 0;
+
+               case WSDISPLAYIO_SMODE:
+                       {
+                               int new_mode = *(int*)data;
+
+                               /* notify the bus backend */
+                               if (new_mode != sc->sc_mode) {
+                                       sc->sc_mode = new_mode;
+                                       if(new_mode == WSDISPLAYIO_MODE_EMUL) {
+                                               gfb_restore_palette(sc);
+                                               vcons_redraw_screen(ms);
+                                       }
+                               }
+                       }
+                       return 0;
+       }
+       return EPASSTHROUGH;
+}
+
+static paddr_t
+gfb_mmap(void *v, void *vs, off_t offset, int prot)
+{
+       struct vcons_data *vd = v;
+       struct gfb_softc *sc = vd->cookie;
+       paddr_t pa;
+



Home | Main Index | Thread Index | Old Index