Home | History | Annotate | Line # | Download | only in pci
gffb.c revision 1.2
      1  1.2  macallan /*	$NetBSD: gffb.c,v 1.2 2013/10/02 16:35:38 macallan Exp $	*/
      2  1.1  macallan 
      3  1.1  macallan /*
      4  1.1  macallan  * Copyright (c) 2007, 2012 Michael Lorenz
      5  1.1  macallan  * All rights reserved.
      6  1.1  macallan  *
      7  1.1  macallan  * Redistribution and use in source and binary forms, with or without
      8  1.1  macallan  * modification, are permitted provided that the following conditions
      9  1.1  macallan  * are met:
     10  1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     11  1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     12  1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  macallan  *    documentation and/or other materials provided with the distribution.
     15  1.1  macallan  *
     16  1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1  macallan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.1  macallan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.1  macallan  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.1  macallan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  1.1  macallan  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  1.1  macallan  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  1.1  macallan  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  1.1  macallan  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  1.1  macallan  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  1.1  macallan  */
     27  1.1  macallan 
     28  1.1  macallan /*
     29  1.1  macallan  * A console driver for nvidia geforce graphics controllers
     30  1.1  macallan  * tested on macppc only so far
     31  1.1  macallan  */
     32  1.1  macallan 
     33  1.1  macallan #include <sys/cdefs.h>
     34  1.2  macallan __KERNEL_RCSID(0, "$NetBSD: gffb.c,v 1.2 2013/10/02 16:35:38 macallan Exp $");
     35  1.1  macallan 
     36  1.1  macallan #include <sys/param.h>
     37  1.1  macallan #include <sys/systm.h>
     38  1.1  macallan #include <sys/kernel.h>
     39  1.1  macallan #include <sys/device.h>
     40  1.1  macallan #include <sys/malloc.h>
     41  1.1  macallan #include <sys/lwp.h>
     42  1.1  macallan #include <sys/kauth.h>
     43  1.2  macallan #include <sys/atomic.h>
     44  1.1  macallan 
     45  1.1  macallan #include <dev/videomode/videomode.h>
     46  1.1  macallan 
     47  1.1  macallan #include <dev/pci/pcivar.h>
     48  1.1  macallan #include <dev/pci/pcireg.h>
     49  1.1  macallan #include <dev/pci/pcidevs.h>
     50  1.1  macallan #include <dev/pci/pciio.h>
     51  1.1  macallan #include <dev/pci/gffbreg.h>
     52  1.1  macallan 
     53  1.1  macallan #include <dev/wscons/wsdisplayvar.h>
     54  1.1  macallan #include <dev/wscons/wsconsio.h>
     55  1.1  macallan #include <dev/wsfont/wsfont.h>
     56  1.1  macallan #include <dev/rasops/rasops.h>
     57  1.1  macallan #include <dev/wscons/wsdisplay_vconsvar.h>
     58  1.1  macallan #include <dev/pci/wsdisplay_pci.h>
     59  1.1  macallan #include <dev/wscons/wsdisplay_glyphcachevar.h>
     60  1.1  macallan 
     61  1.1  macallan #include <dev/i2c/i2cvar.h>
     62  1.1  macallan 
     63  1.1  macallan #include "opt_gffb.h"
     64  1.1  macallan #include "opt_vcons.h"
     65  1.1  macallan 
     66  1.1  macallan #ifdef GFFB_DEBUG
     67  1.1  macallan #define DPRINTF printf
     68  1.1  macallan #else
     69  1.1  macallan #define DPRINTF while(0) printf
     70  1.1  macallan #endif
     71  1.1  macallan 
     72  1.1  macallan struct gffb_softc {
     73  1.1  macallan 	device_t sc_dev;
     74  1.1  macallan 
     75  1.1  macallan 	pci_chipset_tag_t sc_pc;
     76  1.1  macallan 	pcitag_t sc_pcitag;
     77  1.1  macallan 
     78  1.1  macallan 	bus_space_tag_t sc_memt;
     79  1.1  macallan 	bus_space_tag_t sc_iot;
     80  1.1  macallan 
     81  1.1  macallan 	bus_space_handle_t sc_regh, sc_fbh;
     82  1.1  macallan 	bus_addr_t sc_fb, sc_reg;
     83  1.1  macallan 	bus_size_t sc_fbsize, sc_regsize;
     84  1.1  macallan 	uint8_t *sc_fbaddr;
     85  1.2  macallan 	size_t sc_vramsize;
     86  1.1  macallan 
     87  1.1  macallan 	int sc_width, sc_height, sc_depth, sc_stride;
     88  1.1  macallan 	int sc_locked;
     89  1.1  macallan 	struct vcons_screen sc_console_screen;
     90  1.1  macallan 	struct wsscreen_descr sc_defaultscreen_descr;
     91  1.1  macallan 	const struct wsscreen_descr *sc_screens[1];
     92  1.1  macallan 	struct wsscreen_list sc_screenlist;
     93  1.1  macallan 	struct vcons_data vd;
     94  1.1  macallan 	int sc_mode;
     95  1.1  macallan 	u_char sc_cmap_red[256];
     96  1.1  macallan 	u_char sc_cmap_green[256];
     97  1.1  macallan 	u_char sc_cmap_blue[256];
     98  1.2  macallan 	int sc_put, sc_current, sc_free;
     99  1.1  macallan 	glyphcache sc_gc;
    100  1.1  macallan };
    101  1.1  macallan 
    102  1.1  macallan static int	gffb_match(device_t, cfdata_t, void *);
    103  1.1  macallan static void	gffb_attach(device_t, device_t, void *);
    104  1.1  macallan 
    105  1.1  macallan CFATTACH_DECL_NEW(gffb, sizeof(struct gffb_softc),
    106  1.1  macallan     gffb_match, gffb_attach, NULL, NULL);
    107  1.1  macallan 
    108  1.1  macallan static int	gffb_ioctl(void *, void *, u_long, void *, int,
    109  1.1  macallan 			     struct lwp *);
    110  1.1  macallan static paddr_t	gffb_mmap(void *, void *, off_t, int);
    111  1.1  macallan static void	gffb_init_screen(void *, struct vcons_screen *, int, long *);
    112  1.1  macallan 
    113  1.1  macallan static int	gffb_putcmap(struct gffb_softc *, struct wsdisplay_cmap *);
    114  1.1  macallan static int 	gffb_getcmap(struct gffb_softc *, struct wsdisplay_cmap *);
    115  1.1  macallan static void	gffb_restore_palette(struct gffb_softc *);
    116  1.1  macallan static int 	gffb_putpalreg(struct gffb_softc *, uint8_t, uint8_t,
    117  1.1  macallan 			    uint8_t, uint8_t);
    118  1.1  macallan 
    119  1.1  macallan static void	gffb_init(struct gffb_softc *);
    120  1.1  macallan 
    121  1.2  macallan static void	gffb_make_room(struct gffb_softc *, int);
    122  1.2  macallan 
    123  1.1  macallan #if notyet
    124  1.1  macallan static void	gffb_flush_engine(struct gffb_softc *);
    125  1.1  macallan static void	gffb_rectfill(struct gffb_softc *, int, int, int, int,
    126  1.1  macallan 			    uint32_t);
    127  1.1  macallan static void	gffb_bitblt(void *, int, int, int, int, int,
    128  1.1  macallan 			    int, int);
    129  1.1  macallan 
    130  1.1  macallan static void	gffb_cursor(void *, int, int, int);
    131  1.1  macallan static void	gffb_putchar(void *, int, int, u_int, long);
    132  1.1  macallan static void	gffb_putchar_aa(void *, int, int, u_int, long);
    133  1.1  macallan static void	gffb_copycols(void *, int, int, int, int);
    134  1.1  macallan static void	gffb_erasecols(void *, int, int, int, long);
    135  1.1  macallan static void	gffb_copyrows(void *, int, int, int);
    136  1.1  macallan static void	gffb_eraserows(void *, int, int, long);
    137  1.1  macallan #endif /* notyet */
    138  1.1  macallan 
    139  1.1  macallan struct wsdisplay_accessops gffb_accessops = {
    140  1.1  macallan 	gffb_ioctl,
    141  1.1  macallan 	gffb_mmap,
    142  1.1  macallan 	NULL,	/* alloc_screen */
    143  1.1  macallan 	NULL,	/* free_screen */
    144  1.1  macallan 	NULL,	/* show_screen */
    145  1.1  macallan 	NULL, 	/* load_font */
    146  1.1  macallan 	NULL,	/* pollc */
    147  1.1  macallan 	NULL	/* scroll */
    148  1.1  macallan };
    149  1.1  macallan 
    150  1.1  macallan static int
    151  1.1  macallan gffb_match(device_t parent, cfdata_t match, void *aux)
    152  1.1  macallan {
    153  1.1  macallan 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
    154  1.1  macallan 
    155  1.1  macallan 	if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY)
    156  1.1  macallan 		return 0;
    157  1.1  macallan 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_NVIDIA)
    158  1.1  macallan 		return 0;
    159  1.1  macallan 
    160  1.1  macallan 	/* only card tested on so far - likely need a list */
    161  1.1  macallan 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NVIDIA_GEFORCE2MX)
    162  1.1  macallan 		return 100;
    163  1.1  macallan 	return (0);
    164  1.1  macallan }
    165  1.1  macallan 
    166  1.1  macallan static void
    167  1.1  macallan gffb_attach(device_t parent, device_t self, void *aux)
    168  1.1  macallan {
    169  1.1  macallan 	struct gffb_softc	*sc = device_private(self);
    170  1.1  macallan 	struct pci_attach_args	*pa = aux;
    171  1.1  macallan 	struct rasops_info	*ri;
    172  1.1  macallan 	bus_space_tag_t		tag;
    173  1.1  macallan 	struct wsemuldisplaydev_attach_args aa;
    174  1.1  macallan 	prop_dictionary_t	dict;
    175  1.1  macallan 	unsigned long		defattr;
    176  1.1  macallan 	bool			is_console;
    177  1.1  macallan 	int			i, j;
    178  1.1  macallan 	uint8_t			cmap[768];
    179  1.1  macallan 
    180  1.1  macallan 	sc->sc_pc = pa->pa_pc;
    181  1.1  macallan 	sc->sc_pcitag = pa->pa_tag;
    182  1.1  macallan 	sc->sc_memt = pa->pa_memt;
    183  1.1  macallan 	sc->sc_iot = pa->pa_iot;
    184  1.1  macallan 	sc->sc_dev = self;
    185  1.1  macallan 
    186  1.1  macallan 	pci_aprint_devinfo(pa, NULL);
    187  1.1  macallan 
    188  1.1  macallan 	/* fill in parameters from properties */
    189  1.1  macallan 	dict = device_properties(self);
    190  1.1  macallan 	if (!prop_dictionary_get_uint32(dict, "width", &sc->sc_width)) {
    191  1.1  macallan 		aprint_error("%s: no width property\n", device_xname(self));
    192  1.1  macallan 		return;
    193  1.1  macallan 	}
    194  1.1  macallan 	if (!prop_dictionary_get_uint32(dict, "height", &sc->sc_height)) {
    195  1.1  macallan 		aprint_error("%s: no height property\n", device_xname(self));
    196  1.1  macallan 		return;
    197  1.1  macallan 	}
    198  1.1  macallan 
    199  1.1  macallan #ifdef GLYPHCACHE_DEBUG
    200  1.1  macallan 	/* leave some visible VRAM unused so we can see the glyph cache */
    201  1.1  macallan 	sc->sc_height -= 200;
    202  1.1  macallan #endif
    203  1.1  macallan 
    204  1.1  macallan 	if (!prop_dictionary_get_uint32(dict, "depth", &sc->sc_depth)) {
    205  1.1  macallan 		aprint_error("%s: no depth property\n", device_xname(self));
    206  1.1  macallan 		return;
    207  1.1  macallan 	}
    208  1.1  macallan 	if (!prop_dictionary_get_uint32(dict, "linebytes", &sc->sc_stride)) {
    209  1.1  macallan 		aprint_error("%s: no linebytes property\n",
    210  1.1  macallan 		    device_xname(self));
    211  1.1  macallan 		return;
    212  1.1  macallan 	}
    213  1.1  macallan 
    214  1.1  macallan 	prop_dictionary_get_bool(dict, "is_console", &is_console);
    215  1.1  macallan 
    216  1.1  macallan 	if (pci_mapreg_map(pa, 0x14, PCI_MAPREG_TYPE_MEM,
    217  1.1  macallan 	    BUS_SPACE_MAP_PREFETCHABLE | BUS_SPACE_MAP_LINEAR,
    218  1.1  macallan 	    &tag, &sc->sc_fbh, &sc->sc_fb, &sc->sc_fbsize)) {
    219  1.1  macallan 		aprint_error("%s: failed to map the framebuffer.\n",
    220  1.1  macallan 		    device_xname(sc->sc_dev));
    221  1.1  macallan 	}
    222  1.1  macallan 	sc->sc_fbaddr = bus_space_vaddr(tag, sc->sc_fbh);
    223  1.1  macallan 
    224  1.1  macallan 	if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM, 0,
    225  1.1  macallan 	    &tag, &sc->sc_regh, &sc->sc_reg, &sc->sc_regsize)) {
    226  1.1  macallan 		aprint_error("%s: failed to map registers.\n",
    227  1.1  macallan 		    device_xname(sc->sc_dev));
    228  1.1  macallan 	}
    229  1.1  macallan 
    230  1.1  macallan 	aprint_normal("%s: %d MB aperture at 0x%08x\n", device_xname(self),
    231  1.1  macallan 	    (int)(sc->sc_fbsize >> 20), (uint32_t)sc->sc_fb);
    232  1.1  macallan 
    233  1.1  macallan 	sc->sc_defaultscreen_descr = (struct wsscreen_descr){
    234  1.1  macallan 		"default",
    235  1.1  macallan 		0, 0,
    236  1.1  macallan 		NULL,
    237  1.1  macallan 		8, 16,
    238  1.1  macallan 		WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    239  1.1  macallan 		NULL
    240  1.1  macallan 	};
    241  1.1  macallan 	sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
    242  1.1  macallan 	sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
    243  1.1  macallan 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    244  1.1  macallan 	sc->sc_locked = 0;
    245  1.1  macallan 
    246  1.1  macallan 	vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
    247  1.1  macallan 	    &gffb_accessops);
    248  1.1  macallan 	sc->vd.init_screen = gffb_init_screen;
    249  1.1  macallan 
    250  1.2  macallan 	sc->sc_vramsize = bus_space_read_4(sc->sc_memt, sc->sc_regh,
    251  1.2  macallan 	    GFFB_VRAM) & 0xfff00000;
    252  1.2  macallan 
    253  1.2  macallan 	printf("vram: %d MB\n", sc->sc_vramsize >> 20);
    254  1.2  macallan 	printf("put: %08x\n", bus_space_read_4(sc->sc_memt, sc->sc_regh, GFFB_FIFO_PUT));
    255  1.2  macallan 	printf("get: %08x\n", bus_space_read_4(sc->sc_memt, sc->sc_regh, GFFB_FIFO_GET));
    256  1.1  macallan 	/* init engine here */
    257  1.1  macallan 	gffb_init(sc);
    258  1.2  macallan 	printf("put: %08x\n", bus_space_read_4(sc->sc_memt, sc->sc_regh, GFFB_FIFO_PUT));
    259  1.2  macallan 	printf("get: %08x\n", bus_space_read_4(sc->sc_memt, sc->sc_regh, GFFB_FIFO_GET));
    260  1.1  macallan 
    261  1.1  macallan 	ri = &sc->sc_console_screen.scr_ri;
    262  1.1  macallan 
    263  1.1  macallan #if notyet
    264  1.1  macallan 	sc->sc_gc.gc_bitblt = gffb_bitblt;
    265  1.1  macallan 	sc->sc_gc.gc_blitcookie = sc;
    266  1.1  macallan 	sc->sc_gc.gc_rop = R128_ROP3_S;
    267  1.1  macallan #endif
    268  1.1  macallan 
    269  1.1  macallan 	if (is_console) {
    270  1.1  macallan 		vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
    271  1.1  macallan 		    &defattr);
    272  1.1  macallan 		sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    273  1.1  macallan 
    274  1.1  macallan #if notyet
    275  1.1  macallan 		gffb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
    276  1.1  macallan 		    ri->ri_devcmap[(defattr >> 16) & 0xff]);
    277  1.1  macallan #else
    278  1.2  macallan 		memset(sc->sc_fbaddr + 0x2000,
    279  1.1  macallan 		    ri->ri_devcmap[(defattr >> 16) & 0xff],
    280  1.1  macallan 		    sc->sc_height * sc->sc_stride);
    281  1.1  macallan #endif
    282  1.1  macallan 		sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
    283  1.1  macallan 		sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
    284  1.1  macallan 		sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
    285  1.1  macallan 		sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
    286  1.1  macallan #if notyet
    287  1.1  macallan 		glyphcache_init(&sc->sc_gc, sc->sc_height + 5,
    288  1.1  macallan 				(0x800000 / sc->sc_stride) - sc->sc_height - 5,
    289  1.1  macallan 				sc->sc_width,
    290  1.1  macallan 				ri->ri_font->fontwidth,
    291  1.1  macallan 				ri->ri_font->fontheight,
    292  1.1  macallan 				defattr);
    293  1.1  macallan #endif
    294  1.1  macallan 		wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
    295  1.1  macallan 		    defattr);
    296  1.1  macallan 		vcons_replay_msgbuf(&sc->sc_console_screen);
    297  1.1  macallan 	} else {
    298  1.1  macallan 		/*
    299  1.1  macallan 		 * since we're not the console we can postpone the rest
    300  1.1  macallan 		 * until someone actually allocates a screen for us
    301  1.1  macallan 		 */
    302  1.1  macallan 		if (sc->sc_console_screen.scr_ri.ri_rows == 0) {
    303  1.1  macallan 			/* do some minimal setup to avoid weirdnesses later */
    304  1.1  macallan 			vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
    305  1.1  macallan 			    &defattr);
    306  1.1  macallan 		} else
    307  1.1  macallan 			(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    308  1.1  macallan #if notyet
    309  1.1  macallan 		glyphcache_init(&sc->sc_gc, sc->sc_height + 5,
    310  1.1  macallan 				(0x800000 / sc->sc_stride) - sc->sc_height - 5,
    311  1.1  macallan 				sc->sc_width,
    312  1.1  macallan 				ri->ri_font->fontwidth,
    313  1.1  macallan 				ri->ri_font->fontheight,
    314  1.1  macallan 				defattr);
    315  1.1  macallan #endif
    316  1.1  macallan 	}
    317  1.1  macallan 
    318  1.1  macallan 	j = 0;
    319  1.1  macallan 	rasops_get_cmap(ri, cmap, sizeof(cmap));
    320  1.1  macallan 	for (i = 0; i < 256; i++) {
    321  1.1  macallan 		sc->sc_cmap_red[i] = cmap[j];
    322  1.1  macallan 		sc->sc_cmap_green[i] = cmap[j + 1];
    323  1.1  macallan 		sc->sc_cmap_blue[i] = cmap[j + 2];
    324  1.1  macallan 		gffb_putpalreg(sc, i, cmap[j], cmap[j + 1], cmap[j + 2]);
    325  1.1  macallan 		j += 3;
    326  1.1  macallan 	}
    327  1.1  macallan 
    328  1.1  macallan 	/* no suspend/resume support yet */
    329  1.1  macallan 	pmf_device_register(sc->sc_dev, NULL, NULL);
    330  1.1  macallan 
    331  1.1  macallan 	aa.console = is_console;
    332  1.1  macallan 	aa.scrdata = &sc->sc_screenlist;
    333  1.1  macallan 	aa.accessops = &gffb_accessops;
    334  1.1  macallan 	aa.accesscookie = &sc->vd;
    335  1.1  macallan 
    336  1.1  macallan 	config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
    337  1.1  macallan }
    338  1.1  macallan 
    339  1.1  macallan static int
    340  1.1  macallan gffb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    341  1.1  macallan 	struct lwp *l)
    342  1.1  macallan {
    343  1.1  macallan 	struct vcons_data *vd = v;
    344  1.1  macallan 	struct gffb_softc *sc = vd->cookie;
    345  1.1  macallan 	struct wsdisplay_fbinfo *wdf;
    346  1.1  macallan 	struct vcons_screen *ms = vd->active;
    347  1.1  macallan 
    348  1.1  macallan 	switch (cmd) {
    349  1.1  macallan 	case WSDISPLAYIO_GTYPE:
    350  1.1  macallan 		*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
    351  1.1  macallan 		return 0;
    352  1.1  macallan 
    353  1.1  macallan 	/* PCI config read/write passthrough. */
    354  1.1  macallan 	case PCI_IOC_CFGREAD:
    355  1.1  macallan 	case PCI_IOC_CFGWRITE:
    356  1.1  macallan 		return pci_devioctl(sc->sc_pc, sc->sc_pcitag,
    357  1.1  macallan 		    cmd, data, flag, l);
    358  1.1  macallan 
    359  1.1  macallan 	case WSDISPLAYIO_GET_BUSID:
    360  1.1  macallan 		return wsdisplayio_busid_pci(sc->sc_dev, sc->sc_pc,
    361  1.1  macallan 		    sc->sc_pcitag, data);
    362  1.1  macallan 
    363  1.1  macallan 	case WSDISPLAYIO_GINFO:
    364  1.1  macallan 		if (ms == NULL)
    365  1.1  macallan 			return ENODEV;
    366  1.1  macallan 		wdf = (void *)data;
    367  1.1  macallan 		wdf->height = ms->scr_ri.ri_height;
    368  1.1  macallan 		wdf->width = ms->scr_ri.ri_width;
    369  1.1  macallan 		wdf->depth = ms->scr_ri.ri_depth;
    370  1.1  macallan 		wdf->cmsize = 256;
    371  1.1  macallan 		return 0;
    372  1.1  macallan 
    373  1.1  macallan 	case WSDISPLAYIO_GETCMAP:
    374  1.1  macallan 		return gffb_getcmap(sc,
    375  1.1  macallan 		    (struct wsdisplay_cmap *)data);
    376  1.1  macallan 
    377  1.1  macallan 	case WSDISPLAYIO_PUTCMAP:
    378  1.1  macallan 		return gffb_putcmap(sc,
    379  1.1  macallan 		    (struct wsdisplay_cmap *)data);
    380  1.1  macallan 
    381  1.1  macallan 	case WSDISPLAYIO_LINEBYTES:
    382  1.1  macallan 		*(u_int *)data = sc->sc_stride;
    383  1.1  macallan 		return 0;
    384  1.1  macallan 
    385  1.1  macallan 	case WSDISPLAYIO_SMODE: {
    386  1.1  macallan 		int new_mode = *(int*)data;
    387  1.1  macallan 		if (new_mode != sc->sc_mode) {
    388  1.1  macallan 			sc->sc_mode = new_mode;
    389  1.1  macallan 			if(new_mode == WSDISPLAYIO_MODE_EMUL) {
    390  1.1  macallan 				gffb_init(sc);
    391  1.1  macallan 				gffb_restore_palette(sc);
    392  1.1  macallan #if notyet
    393  1.1  macallan 				glyphcache_wipe(&sc->sc_gc);
    394  1.1  macallan 				gffb_rectfill(sc, 0, 0, sc->sc_width,
    395  1.1  macallan 				    sc->sc_height, ms->scr_ri.ri_devcmap[
    396  1.1  macallan 				    (ms->scr_defattr >> 16) & 0xff]);
    397  1.1  macallan #endif
    398  1.1  macallan 				vcons_redraw_screen(ms);
    399  1.1  macallan 			}
    400  1.1  macallan 		}
    401  1.1  macallan 		}
    402  1.1  macallan 		return 0;
    403  1.1  macallan #if notyet
    404  1.1  macallan 	case WSDISPLAYIO_GET_EDID: {
    405  1.1  macallan 		struct wsdisplayio_edid_info *d = data;
    406  1.1  macallan 		return wsdisplayio_get_edid(sc->sc_dev, d);
    407  1.1  macallan 	}
    408  1.1  macallan #endif
    409  1.1  macallan 	}
    410  1.1  macallan 	return EPASSTHROUGH;
    411  1.1  macallan }
    412  1.1  macallan 
    413  1.1  macallan static paddr_t
    414  1.1  macallan gffb_mmap(void *v, void *vs, off_t offset, int prot)
    415  1.1  macallan {
    416  1.1  macallan 	struct vcons_data *vd = v;
    417  1.1  macallan 	struct gffb_softc *sc = vd->cookie;
    418  1.1  macallan 	paddr_t pa;
    419  1.1  macallan 
    420  1.1  macallan 	/* 'regular' framebuffer mmap()ing */
    421  1.1  macallan 	if (offset < sc->sc_fbsize) {
    422  1.2  macallan 		pa = bus_space_mmap(sc->sc_memt, sc->sc_fb + offset + 0x2000,
    423  1.2  macallan 		    0, prot, BUS_SPACE_MAP_LINEAR);
    424  1.1  macallan 		return pa;
    425  1.1  macallan 	}
    426  1.1  macallan 
    427  1.1  macallan 	/*
    428  1.1  macallan 	 * restrict all other mappings to processes with superuser privileges
    429  1.1  macallan 	 * or the kernel itself
    430  1.1  macallan 	 */
    431  1.1  macallan 	if (kauth_authorize_machdep(kauth_cred_get(), KAUTH_MACHDEP_UNMANAGEDMEM,
    432  1.1  macallan 	    NULL, NULL, NULL, NULL) != 0) {
    433  1.1  macallan 		aprint_normal("%s: mmap() rejected.\n",
    434  1.1  macallan 		    device_xname(sc->sc_dev));
    435  1.1  macallan 		return -1;
    436  1.1  macallan 	}
    437  1.1  macallan 
    438  1.1  macallan 	if ((offset >= sc->sc_fb) && (offset < (sc->sc_fb + sc->sc_fbsize))) {
    439  1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
    440  1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
    441  1.1  macallan 		return pa;
    442  1.1  macallan 	}
    443  1.1  macallan 
    444  1.1  macallan 	if ((offset >= sc->sc_reg) &&
    445  1.1  macallan 	    (offset < (sc->sc_reg + sc->sc_regsize))) {
    446  1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
    447  1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
    448  1.1  macallan 		return pa;
    449  1.1  macallan 	}
    450  1.1  macallan 
    451  1.1  macallan #ifdef PCI_MAGIC_IO_RANGE
    452  1.1  macallan 	/* allow mapping of IO space */
    453  1.1  macallan 	if ((offset >= PCI_MAGIC_IO_RANGE) &&
    454  1.1  macallan 	    (offset < PCI_MAGIC_IO_RANGE + 0x10000)) {
    455  1.1  macallan 		pa = bus_space_mmap(sc->sc_iot, offset - PCI_MAGIC_IO_RANGE,
    456  1.1  macallan 		    0, prot, BUS_SPACE_MAP_LINEAR);
    457  1.1  macallan 		return pa;
    458  1.1  macallan 	}
    459  1.1  macallan #endif
    460  1.1  macallan 
    461  1.1  macallan #ifdef OFB_ALLOW_OTHERS
    462  1.1  macallan 	if (offset >= 0x80000000) {
    463  1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
    464  1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
    465  1.1  macallan 		return pa;
    466  1.1  macallan 	}
    467  1.1  macallan #endif
    468  1.1  macallan 	return -1;
    469  1.1  macallan }
    470  1.1  macallan 
    471  1.1  macallan static void
    472  1.1  macallan gffb_init_screen(void *cookie, struct vcons_screen *scr,
    473  1.1  macallan     int existing, long *defattr)
    474  1.1  macallan {
    475  1.1  macallan 	struct gffb_softc *sc = cookie;
    476  1.1  macallan 	struct rasops_info *ri = &scr->scr_ri;
    477  1.1  macallan 
    478  1.1  macallan 	ri->ri_depth = sc->sc_depth;
    479  1.1  macallan 	ri->ri_width = sc->sc_width;
    480  1.1  macallan 	ri->ri_height = sc->sc_height;
    481  1.1  macallan 	ri->ri_stride = sc->sc_stride;
    482  1.2  macallan 	ri->ri_bits = sc->sc_fbaddr + 0x2000;
    483  1.1  macallan 	ri->ri_flg = RI_CENTER;
    484  1.1  macallan 	if (sc->sc_depth == 8)
    485  1.1  macallan 		ri->ri_flg |= RI_8BIT_IS_RGB | RI_ENABLE_ALPHA;
    486  1.1  macallan 
    487  1.1  macallan 	rasops_init(ri, 0, 0);
    488  1.1  macallan 	ri->ri_caps = WSSCREEN_WSCOLORS;
    489  1.1  macallan 	scr->scr_flags |= VCONS_DONT_READ;
    490  1.1  macallan 
    491  1.1  macallan 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
    492  1.1  macallan 		    sc->sc_width / ri->ri_font->fontwidth);
    493  1.1  macallan 
    494  1.1  macallan 	ri->ri_hw = scr;
    495  1.1  macallan #if notyet
    496  1.1  macallan 	ri->ri_ops.copyrows = gffb_copyrows;
    497  1.1  macallan 	ri->ri_ops.copycols = gffb_copycols;
    498  1.1  macallan 	ri->ri_ops.eraserows = gffb_eraserows;
    499  1.1  macallan 	ri->ri_ops.erasecols = gffb_erasecols;
    500  1.1  macallan 	ri->ri_ops.cursor = gffb_cursor;
    501  1.1  macallan 	if (FONT_IS_ALPHA(ri->ri_font)) {
    502  1.1  macallan 		ri->ri_ops.putchar = gffb_putchar_aa;
    503  1.1  macallan 	} else
    504  1.1  macallan 		ri->ri_ops.putchar = gffb_putchar;
    505  1.1  macallan #endif
    506  1.1  macallan }
    507  1.1  macallan 
    508  1.1  macallan static int
    509  1.1  macallan gffb_putcmap(struct gffb_softc *sc, struct wsdisplay_cmap *cm)
    510  1.1  macallan {
    511  1.1  macallan 	u_char *r, *g, *b;
    512  1.1  macallan 	u_int index = cm->index;
    513  1.1  macallan 	u_int count = cm->count;
    514  1.1  macallan 	int i, error;
    515  1.1  macallan 	u_char rbuf[256], gbuf[256], bbuf[256];
    516  1.1  macallan 
    517  1.1  macallan #ifdef R128FB_DEBUG
    518  1.1  macallan 	aprint_debug("putcmap: %d %d\n",index, count);
    519  1.1  macallan #endif
    520  1.1  macallan 	if (cm->index >= 256 || cm->count > 256 ||
    521  1.1  macallan 	    (cm->index + cm->count) > 256)
    522  1.1  macallan 		return EINVAL;
    523  1.1  macallan 	error = copyin(cm->red, &rbuf[index], count);
    524  1.1  macallan 	if (error)
    525  1.1  macallan 		return error;
    526  1.1  macallan 	error = copyin(cm->green, &gbuf[index], count);
    527  1.1  macallan 	if (error)
    528  1.1  macallan 		return error;
    529  1.1  macallan 	error = copyin(cm->blue, &bbuf[index], count);
    530  1.1  macallan 	if (error)
    531  1.1  macallan 		return error;
    532  1.1  macallan 
    533  1.1  macallan 	memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
    534  1.1  macallan 	memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
    535  1.1  macallan 	memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
    536  1.1  macallan 
    537  1.1  macallan 	r = &sc->sc_cmap_red[index];
    538  1.1  macallan 	g = &sc->sc_cmap_green[index];
    539  1.1  macallan 	b = &sc->sc_cmap_blue[index];
    540  1.1  macallan 
    541  1.1  macallan 	for (i = 0; i < count; i++) {
    542  1.1  macallan 		gffb_putpalreg(sc, index, *r, *g, *b);
    543  1.1  macallan 		index++;
    544  1.1  macallan 		r++, g++, b++;
    545  1.1  macallan 	}
    546  1.1  macallan 	return 0;
    547  1.1  macallan }
    548  1.1  macallan 
    549  1.1  macallan static int
    550  1.1  macallan gffb_getcmap(struct gffb_softc *sc, struct wsdisplay_cmap *cm)
    551  1.1  macallan {
    552  1.1  macallan 	u_int index = cm->index;
    553  1.1  macallan 	u_int count = cm->count;
    554  1.1  macallan 	int error;
    555  1.1  macallan 
    556  1.1  macallan 	if (index >= 255 || count > 256 || index + count > 256)
    557  1.1  macallan 		return EINVAL;
    558  1.1  macallan 
    559  1.1  macallan 	error = copyout(&sc->sc_cmap_red[index],   cm->red,   count);
    560  1.1  macallan 	if (error)
    561  1.1  macallan 		return error;
    562  1.1  macallan 	error = copyout(&sc->sc_cmap_green[index], cm->green, count);
    563  1.1  macallan 	if (error)
    564  1.1  macallan 		return error;
    565  1.1  macallan 	error = copyout(&sc->sc_cmap_blue[index],  cm->blue,  count);
    566  1.1  macallan 	if (error)
    567  1.1  macallan 		return error;
    568  1.1  macallan 
    569  1.1  macallan 	return 0;
    570  1.1  macallan }
    571  1.1  macallan 
    572  1.1  macallan static void
    573  1.1  macallan gffb_restore_palette(struct gffb_softc *sc)
    574  1.1  macallan {
    575  1.1  macallan 	int i;
    576  1.1  macallan 
    577  1.1  macallan 	for (i = 0; i < (1 << sc->sc_depth); i++) {
    578  1.1  macallan 		gffb_putpalreg(sc, i, sc->sc_cmap_red[i],
    579  1.1  macallan 		    sc->sc_cmap_green[i], sc->sc_cmap_blue[i]);
    580  1.1  macallan 	}
    581  1.1  macallan }
    582  1.1  macallan 
    583  1.1  macallan static int
    584  1.1  macallan gffb_putpalreg(struct gffb_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
    585  1.1  macallan     uint8_t b)
    586  1.1  macallan {
    587  1.1  macallan 	/* port 0 */
    588  1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh,
    589  1.1  macallan 	    GFFB_PDIO0 + GFFB_PEL_IW, idx);
    590  1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh,
    591  1.1  macallan 	    GFFB_PDIO0 + GFFB_PEL_D, r);
    592  1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh,
    593  1.1  macallan 	    GFFB_PDIO0 + GFFB_PEL_D, g);
    594  1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh,
    595  1.1  macallan 	    GFFB_PDIO0 + GFFB_PEL_D, b);
    596  1.1  macallan 
    597  1.1  macallan 	/* port 1 */
    598  1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh,
    599  1.1  macallan 	    GFFB_PDIO1 + GFFB_PEL_IW, idx);
    600  1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh,
    601  1.1  macallan 	    GFFB_PDIO1 + GFFB_PEL_D, r);
    602  1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh,
    603  1.1  macallan 	    GFFB_PDIO1 + GFFB_PEL_D, g);
    604  1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh,
    605  1.1  macallan 	    GFFB_PDIO1 + GFFB_PEL_D, b);
    606  1.1  macallan 
    607  1.1  macallan 	return 0;
    608  1.1  macallan }
    609  1.1  macallan 
    610  1.2  macallan 
    611  1.2  macallan static void
    612  1.2  macallan gffb_dma_kickoff(struct gffb_softc *sc)
    613  1.2  macallan {
    614  1.2  macallan 	volatile uint8_t scratch;
    615  1.2  macallan 
    616  1.2  macallan 	if(sc->sc_current != sc->sc_put) {
    617  1.2  macallan 		sc->sc_put = sc->sc_current;
    618  1.2  macallan 		membar_sync();
    619  1.2  macallan 		scratch = *sc->sc_fbaddr;
    620  1.2  macallan 		bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_FIFO_PUT,
    621  1.2  macallan 		    sc->sc_put);
    622  1.2  macallan 	}
    623  1.2  macallan }
    624  1.2  macallan 
    625  1.2  macallan static void
    626  1.2  macallan gffb_dmanext(struct gffb_softc *sc, uint32_t data)
    627  1.2  macallan {
    628  1.2  macallan 	bus_space_write_stream_4(sc->sc_memt, sc->sc_fbh, sc->sc_current, data);
    629  1.2  macallan 	sc->sc_current += 4;
    630  1.2  macallan }
    631  1.2  macallan 
    632  1.2  macallan static void
    633  1.2  macallan gffb_dmastart(struct gffb_softc *sc, uint32_t tag, int size)
    634  1.2  macallan {
    635  1.2  macallan 	if(sc->sc_free <= (size << 2))
    636  1.2  macallan 		gffb_make_room(sc, size);
    637  1.2  macallan 	gffb_dmanext(sc, ((size) << 18) | (tag));
    638  1.2  macallan 	sc->sc_free -= ((size + 1) << 2);
    639  1.2  macallan }
    640  1.2  macallan 
    641  1.2  macallan /*
    642  1.2  macallan  * from xf86_video_nv/nv_xaa.c:
    643  1.2  macallan  * There is a HW race condition with videoram command buffers.
    644  1.2  macallan  * You can't jump to the location of your put offset.  We write put
    645  1.2  macallan  * at the jump offset + SKIPS dwords with noop padding in between
    646  1.2  macallan  * to solve this problem
    647  1.2  macallan  */
    648  1.2  macallan 
    649  1.2  macallan #define SKIPS  8
    650  1.2  macallan 
    651  1.2  macallan static void
    652  1.2  macallan gffb_make_room(struct gffb_softc *sc, int size)
    653  1.2  macallan {
    654  1.2  macallan 	uint32_t get;
    655  1.2  macallan 
    656  1.2  macallan 	size = (size + 1) << 2;	/* slots -> offset */
    657  1.2  macallan 
    658  1.2  macallan 	while (sc->sc_free < size) {
    659  1.2  macallan 		get = bus_space_read_4(sc->sc_memt, sc->sc_regh, GFFB_FIFO_GET);
    660  1.2  macallan 
    661  1.2  macallan 		if (sc->sc_put >= get) {
    662  1.2  macallan 			sc->sc_free = 0x2000 - sc->sc_current;
    663  1.2  macallan 			if (sc->sc_free < size) {
    664  1.2  macallan 				gffb_dmanext(sc, 0x20000000);
    665  1.2  macallan 				if(get <= SKIPS) {
    666  1.2  macallan 					if (sc->sc_put <= SKIPS) {
    667  1.2  macallan 						/* corner case - will be idle */
    668  1.2  macallan 						bus_space_write_4(sc->sc_memt,
    669  1.2  macallan 						    sc->sc_regh, GFFB_FIFO_PUT,
    670  1.2  macallan 						    SKIPS + 1);
    671  1.2  macallan 					}
    672  1.2  macallan 					do {
    673  1.2  macallan 						get = bus_space_read_4(
    674  1.2  macallan 						    sc->sc_memt, sc->sc_regh,
    675  1.2  macallan 						    GFFB_FIFO_GET);
    676  1.2  macallan 					} while (get <= SKIPS);
    677  1.2  macallan 				}
    678  1.2  macallan 				bus_space_write_4(sc->sc_memt, sc->sc_regh,
    679  1.2  macallan 				     GFFB_FIFO_PUT, SKIPS);
    680  1.2  macallan 				sc->sc_current = sc->sc_put = SKIPS;
    681  1.2  macallan 				sc->sc_free = get - (SKIPS + 1);
    682  1.2  macallan 			}
    683  1.2  macallan 		} else
    684  1.2  macallan 			sc->sc_free = get - sc->sc_current - 1;
    685  1.2  macallan 	}
    686  1.2  macallan }
    687  1.2  macallan 
    688  1.1  macallan static void
    689  1.2  macallan gffb_sync(struct gffb_softc *sc)
    690  1.1  macallan {
    691  1.2  macallan 	int bail;
    692  1.1  macallan 
    693  1.2  macallan 	bail = 100000;
    694  1.2  macallan 	while ((bus_space_read_4(sc->sc_memt, sc->sc_regh, GFFB_FIFO_GET) !=
    695  1.2  macallan 	    sc->sc_put) && (bail > 0)) {
    696  1.2  macallan 		bail--;
    697  1.2  macallan 		delay(1);
    698  1.2  macallan 	}
    699  1.2  macallan 	if (bail == 0) printf("DMA timed out\n");
    700  1.2  macallan 
    701  1.2  macallan 	bail = 100000;
    702  1.2  macallan 	while((bus_space_read_4(sc->sc_memt, sc->sc_regh, GFFB_BUSY) != 0) &&
    703  1.2  macallan 	    (bail > 0)) {
    704  1.2  macallan 		bail--;
    705  1.2  macallan 		delay(1);
    706  1.1  macallan 	}
    707  1.2  macallan 	if (bail == 0) printf("engine timed out\n");
    708  1.2  macallan }
    709  1.2  macallan 
    710  1.2  macallan static void
    711  1.2  macallan gffb_init(struct gffb_softc *sc)
    712  1.2  macallan {
    713  1.2  macallan 	int i;
    714  1.1  macallan 
    715  1.1  macallan 	/* init display start */
    716  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh,
    717  1.2  macallan 	    GFFB_CRTC0 + GFFB_DISPLAYSTART, 0x2000);
    718  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh,
    719  1.2  macallan 	    GFFB_CRTC1 + GFFB_DISPLAYSTART, 0x2000);
    720  1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh,
    721  1.1  macallan 	    GFFB_PDIO0 + GFFB_PEL_MASK, 0xff);
    722  1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh,
    723  1.1  macallan 	    GFFB_PDIO1 + GFFB_PEL_MASK, 0xff);
    724  1.2  macallan 
    725  1.2  macallan 	/* DMA stuff. A whole lot of magic number voodoo from xf86-video-nv */
    726  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PMC + 0x140, 0);
    727  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PMC + 0x200, 0xffff00ff);
    728  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PMC + 0x200, 0xffffffff);
    729  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PTIMER + 0x800, 8);
    730  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PTIMER + 0x840, 3);
    731  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PTIMER + 0x500, 0);
    732  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PTIMER + 0x400, 0xffffffff);
    733  1.2  macallan 	for (i = 0; i < 8; i++) {
    734  1.2  macallan 		bus_space_write_4(sc->sc_memt, sc->sc_regh,
    735  1.2  macallan 		    GFFB_PMC + 0x240 + (i * 0x10), 0);
    736  1.2  macallan 		bus_space_write_4(sc->sc_memt, sc->sc_regh,
    737  1.2  macallan 		    GFFB_PMC + 0x244 + (i * 0x10), sc->sc_vramsize - 1);
    738  1.2  macallan 	}
    739  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN, 0x80000010);
    740  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x04, 0x80011201);
    741  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x08, 0x80000011);
    742  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x0c, 0x80011202);
    743  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x10, 0x80000012);
    744  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x14, 0x80011203);
    745  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x18, 0x80000013);
    746  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x1c, 0x80011204);
    747  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x20, 0x80000014);
    748  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x24, 0x80011205);
    749  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x28, 0x80000015);
    750  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2c, 0x80011206);
    751  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x30, 0x80000016);
    752  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x34, 0x80011207);
    753  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x38, 0x80000017);
    754  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x3c, 0x80011208);
    755  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2000, 0x00003000);
    756  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2004, sc->sc_vramsize - 1);
    757  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2008, 0x00000002);
    758  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x200c, 0x00000002);
    759  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2010, 0x01008042);	/* different for nv40 */
    760  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2014, 0);
    761  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2018, 0x12001200);
    762  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x201c, 0);
    763  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2020, 0x01008043);
    764  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2024, 0);
    765  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2028, 0);
    766  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x202c, 0);
    767  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2030, 0x01008044);
    768  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2034, 0x00000002);
    769  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2038, 0);
    770  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x203c, 0);
    771  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2040, 0x01008019);
    772  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2044, 0);
    773  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2048, 0);
    774  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x204c, 0);
    775  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2050, 0x0100a05c);
    776  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2054, 0);
    777  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2058, 0);
    778  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x205c, 0);
    779  1.2  macallan 	/* XXX 0x0100805f if !WaitVSynvPossible */
    780  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2060, 0x0100809f);
    781  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2064, 0);
    782  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2068, 0x12001200);
    783  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x206c, 0);
    784  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2070, 0x0100804a);
    785  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2074, 0x00000002);
    786  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2078, 0);
    787  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x207c, 0);
    788  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2080, 0x01018077);
    789  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2084, 0);
    790  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2088, 0x12001200);
    791  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x208c, 0);
    792  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2090, 0x00003002);
    793  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2094, 0x00007fff);
    794  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x2098, 0x00000002);	/* start of command buffer? */
    795  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PRAMIN + 0x209c, 0x00000002);
    796  1.2  macallan 	/* __BIG_ENDIAN part? */
    797  1.2  macallan 	/* PGRAPH setup */
    798  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x0500, 0);
    799  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x0504, 0x00000001);
    800  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1200, 0);
    801  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1250, 0);
    802  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1204, 0x00000100);	/* different on nv40 */
    803  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1240, 0);
    804  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1244, 0);
    805  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x122c, 0x00001209);	/* different on nv40 */
    806  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1000, 0);
    807  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1050, 0);
    808  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x0210, 0x03000100);
    809  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x0214, 0x00000110);
    810  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x0218, 0x00000112);
    811  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x050c, 0x0000ffff);
    812  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1258, 0x0000ffff);
    813  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x0140, 0);
    814  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x0100, 0xffffffff);
    815  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1054, 0x00000001);
    816  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1230, 0);
    817  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1280, 0);
    818  1.2  macallan #if BYTE_ORDER == BIG_ENDIAN
    819  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1224, 0x800f0078);
    820  1.2  macallan #else
    821  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1224, 0x000f0078);
    822  1.2  macallan #endif
    823  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1220, 0x00000001);
    824  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1200, 0x00000001);
    825  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1250, 0x00000001);
    826  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x1254, 0x00000001);
    827  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_PFIFO + 0x0500, 0x00000001);
    828  1.2  macallan 
    829  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_CMDSTART, 0x00000002);
    830  1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, GFFB_FIFO_GET, 0);
    831  1.2  macallan 	sc->sc_put = 0;
    832  1.2  macallan 	sc->sc_current = 0;
    833  1.2  macallan 	sc->sc_free = 0x2000;
    834  1.2  macallan 
    835  1.2  macallan 	for(i = 0; i < SKIPS; i++)
    836  1.2  macallan 		gffb_dmanext(sc, 0);
    837  1.2  macallan 
    838  1.2  macallan 	gffb_dmanext(sc, 0x00040000);
    839  1.2  macallan 	gffb_dmanext(sc, 0x80000010);
    840  1.2  macallan 	gffb_dmanext(sc, 0x00042000);
    841  1.2  macallan 	gffb_dmanext(sc, 0x80000011);
    842  1.2  macallan 	gffb_dmanext(sc, 0x00044000);
    843  1.2  macallan 	gffb_dmanext(sc, 0x80000012);
    844  1.2  macallan 	gffb_dmanext(sc, 0x00046000);
    845  1.2  macallan 	gffb_dmanext(sc, 0x80000013);
    846  1.2  macallan 	gffb_dmanext(sc, 0x00048000);
    847  1.2  macallan 	gffb_dmanext(sc, 0x80000014);
    848  1.2  macallan 	gffb_dmanext(sc, 0x0004A000);
    849  1.2  macallan 	gffb_dmanext(sc, 0x80000015);
    850  1.2  macallan 	gffb_dmanext(sc, 0x0004C000);
    851  1.2  macallan 	gffb_dmanext(sc, 0x80000016);
    852  1.2  macallan 	gffb_dmanext(sc, 0x0004E000);
    853  1.2  macallan 	gffb_dmanext(sc, 0x80000017);
    854  1.2  macallan 	sc->sc_free = 0x2000 - sc->sc_current;
    855  1.2  macallan 
    856  1.2  macallan 	gffb_dmastart(sc, SURFACE_FORMAT, 4);
    857  1.2  macallan 	gffb_dmanext(sc, SURFACE_FORMAT_DEPTH8);
    858  1.2  macallan 	gffb_dmanext(sc, sc->sc_stride | (sc->sc_stride << 16));
    859  1.2  macallan 	gffb_dmanext(sc, 0);
    860  1.2  macallan 	gffb_dmanext(sc, 0);
    861  1.2  macallan 
    862  1.2  macallan 	gffb_dmastart(sc, RECT_FORMAT, 1);
    863  1.2  macallan 	gffb_dmanext(sc, RECT_FORMAT_DEPTH8);
    864  1.2  macallan 
    865  1.2  macallan 	gffb_dmastart(sc, ROP_SET, 1);
    866  1.2  macallan 	gffb_dmanext(sc, 0xcc);
    867  1.2  macallan 
    868  1.2  macallan 	gffb_dma_kickoff(sc);
    869  1.2  macallan 	gffb_sync(sc);
    870  1.2  macallan 	printf("put %x current %x\n", sc->sc_put, sc->sc_current);
    871  1.1  macallan }
    872  1.2  macallan 
    873