Home | History | Annotate | Line # | Download | only in dev
crmfb.c revision 1.29
      1  1.29  macallan /* $NetBSD: crmfb.c,v 1.29 2011/03/30 19:16:35 macallan Exp $ */
      2   1.1  jmcneill 
      3   1.1  jmcneill /*-
      4   1.1  jmcneill  * Copyright (c) 2007 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  1.12  macallan  *               2008 Michael Lorenz <macallan (at) netbsd.org>
      6   1.1  jmcneill  * All rights reserved.
      7   1.1  jmcneill  *
      8   1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      9   1.1  jmcneill  * modification, are permitted provided that the following conditions
     10   1.1  jmcneill  * are met:
     11   1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     12   1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     13   1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     15   1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     16   1.1  jmcneill  *
     17   1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18   1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19   1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20   1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21   1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22   1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23   1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24   1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25   1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26   1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27   1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     28   1.1  jmcneill  */
     29   1.1  jmcneill 
     30   1.1  jmcneill /*
     31   1.1  jmcneill  * SGI-CRM (O2) Framebuffer driver
     32   1.1  jmcneill  */
     33   1.1  jmcneill 
     34   1.1  jmcneill #include <sys/cdefs.h>
     35  1.29  macallan __KERNEL_RCSID(0, "$NetBSD: crmfb.c,v 1.29 2011/03/30 19:16:35 macallan Exp $");
     36   1.1  jmcneill 
     37   1.1  jmcneill #include <sys/param.h>
     38   1.1  jmcneill #include <sys/systm.h>
     39   1.1  jmcneill #include <sys/device.h>
     40   1.1  jmcneill #include <sys/malloc.h>
     41   1.1  jmcneill 
     42   1.1  jmcneill #define _SGIMIPS_BUS_DMA_PRIVATE
     43   1.1  jmcneill #include <machine/autoconf.h>
     44   1.1  jmcneill #include <machine/bus.h>
     45   1.1  jmcneill #include <machine/machtype.h>
     46   1.1  jmcneill #include <machine/vmparam.h>
     47   1.1  jmcneill 
     48   1.2  jmcneill #include <dev/arcbios/arcbios.h>
     49   1.2  jmcneill #include <dev/arcbios/arcbiosvar.h>
     50   1.2  jmcneill 
     51   1.1  jmcneill #include <dev/wscons/wsdisplayvar.h>
     52   1.1  jmcneill #include <dev/wscons/wsconsio.h>
     53   1.1  jmcneill #include <dev/wsfont/wsfont.h>
     54   1.1  jmcneill #include <dev/rasops/rasops.h>
     55   1.1  jmcneill #include <dev/wscons/wsdisplay_vconsvar.h>
     56   1.1  jmcneill 
     57   1.7  macallan #include <arch/sgimips/dev/crmfbreg.h>
     58   1.7  macallan 
     59  1.18  macallan /*#define CRMFB_DEBUG*/
     60   1.3  jmcneill 
     61   1.1  jmcneill struct wsscreen_descr crmfb_defaultscreen = {
     62   1.1  jmcneill 	"default",
     63   1.1  jmcneill 	0, 0,
     64   1.1  jmcneill 	NULL,
     65   1.1  jmcneill 	8, 16,
     66   1.1  jmcneill 	WSSCREEN_WSCOLORS,
     67   1.1  jmcneill 	NULL,
     68   1.1  jmcneill };
     69   1.1  jmcneill 
     70   1.1  jmcneill const struct wsscreen_descr *_crmfb_scrlist[] = {
     71   1.1  jmcneill 	&crmfb_defaultscreen,
     72   1.1  jmcneill };
     73   1.1  jmcneill 
     74   1.1  jmcneill struct wsscreen_list crmfb_screenlist = {
     75   1.1  jmcneill 	sizeof(_crmfb_scrlist) / sizeof(struct wsscreen_descr *),
     76   1.1  jmcneill 	_crmfb_scrlist
     77   1.1  jmcneill };
     78   1.1  jmcneill 
     79   1.1  jmcneill static struct vcons_screen crmfb_console_screen;
     80   1.1  jmcneill 
     81   1.1  jmcneill static int	crmfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     82   1.1  jmcneill static paddr_t	crmfb_mmap(void *, void *, off_t, int);
     83   1.1  jmcneill static void	crmfb_init_screen(void *, struct vcons_screen *, int, long *);
     84   1.1  jmcneill 
     85   1.1  jmcneill struct wsdisplay_accessops crmfb_accessops = {
     86   1.1  jmcneill 	crmfb_ioctl,
     87   1.1  jmcneill 	crmfb_mmap,
     88   1.1  jmcneill 	NULL,	/* alloc_screen */
     89   1.1  jmcneill 	NULL,	/* free_screen */
     90   1.1  jmcneill 	NULL,	/* show_screen */
     91   1.1  jmcneill 	NULL,	/* load_font */
     92   1.1  jmcneill 	NULL,	/* pollc */
     93   1.1  jmcneill 	NULL,	/* scroll */
     94   1.1  jmcneill };
     95   1.1  jmcneill 
     96   1.1  jmcneill /* Memory to allocate to SGI-CRM -- remember, this is stolen from
     97   1.1  jmcneill  * host memory!
     98   1.1  jmcneill  */
     99   1.1  jmcneill #define CRMFB_TILESIZE	(512*128)
    100   1.1  jmcneill 
    101  1.29  macallan static int	crmfb_match(device_t, struct cfdata *, void *);
    102  1.29  macallan static void	crmfb_attach(device_t, device_t, void *);
    103   1.1  jmcneill int		crmfb_probe(void);
    104   1.1  jmcneill 
    105   1.1  jmcneill #define KERNADDR(p)	((void *)((p).addr))
    106   1.1  jmcneill #define DMAADDR(p)	((p).map->dm_segs[0].ds_addr)
    107   1.1  jmcneill 
    108  1.10    sekiya #define CRMFB_REG_MASK(msb, lsb) \
    109  1.10    sekiya 	( (((uint32_t) 1 << ((msb)-(lsb)+1)) - 1) << (lsb) )
    110  1.10    sekiya 
    111  1.10    sekiya 
    112   1.1  jmcneill struct crmfb_dma {
    113   1.1  jmcneill 	bus_dmamap_t		map;
    114   1.1  jmcneill 	void			*addr;
    115   1.1  jmcneill 	bus_dma_segment_t	segs[1];
    116   1.1  jmcneill 	int			nsegs;
    117   1.1  jmcneill 	size_t			size;
    118   1.1  jmcneill };
    119   1.1  jmcneill 
    120   1.1  jmcneill struct crmfb_softc {
    121  1.29  macallan 	device_t		sc_dev;
    122   1.1  jmcneill 	struct vcons_data	sc_vd;
    123   1.1  jmcneill 
    124   1.1  jmcneill 	bus_space_tag_t		sc_iot;
    125   1.1  jmcneill 	bus_space_handle_t	sc_ioh;
    126  1.11  macallan 	bus_space_handle_t	sc_reh;
    127   1.7  macallan 
    128   1.1  jmcneill 	bus_dma_tag_t		sc_dmat;
    129   1.1  jmcneill 
    130   1.1  jmcneill 	struct crmfb_dma	sc_dma;
    131   1.1  jmcneill 	struct crmfb_dma	sc_dmai;
    132   1.1  jmcneill 
    133   1.1  jmcneill 	int			sc_width;
    134   1.1  jmcneill 	int			sc_height;
    135   1.1  jmcneill 	int			sc_depth;
    136  1.11  macallan 	int			sc_tiles_x, sc_tiles_y;
    137   1.1  jmcneill 	uint32_t		sc_fbsize;
    138  1.18  macallan 	int			sc_mte_direction;
    139  1.11  macallan 	uint8_t			*sc_scratch;
    140  1.21  macallan 	paddr_t			sc_linear;
    141   1.1  jmcneill 	int			sc_wsmode;
    142   1.6  macallan 
    143   1.6  macallan 	/* cursor stuff */
    144   1.6  macallan 	int			sc_cur_x;
    145   1.6  macallan 	int			sc_cur_y;
    146   1.6  macallan 	int			sc_hot_x;
    147   1.6  macallan 	int			sc_hot_y;
    148   1.6  macallan 
    149   1.1  jmcneill 	u_char			sc_cmap_red[256];
    150   1.1  jmcneill 	u_char			sc_cmap_green[256];
    151   1.1  jmcneill 	u_char			sc_cmap_blue[256];
    152   1.1  jmcneill };
    153   1.1  jmcneill 
    154   1.1  jmcneill static int	crmfb_putcmap(struct crmfb_softc *, struct wsdisplay_cmap *);
    155   1.1  jmcneill static int	crmfb_getcmap(struct crmfb_softc *, struct wsdisplay_cmap *);
    156   1.1  jmcneill static void	crmfb_set_palette(struct crmfb_softc *,
    157   1.1  jmcneill 				  int, uint8_t, uint8_t, uint8_t);
    158   1.6  macallan static int	crmfb_set_curpos(struct crmfb_softc *, int, int);
    159   1.6  macallan static int	crmfb_gcursor(struct crmfb_softc *, struct wsdisplay_cursor *);
    160   1.6  macallan static int	crmfb_scursor(struct crmfb_softc *, struct wsdisplay_cursor *);
    161   1.7  macallan static inline void	crmfb_write_reg(struct crmfb_softc *, int, uint32_t);
    162  1.11  macallan static inline uint32_t	crmfb_read_reg(struct crmfb_softc *, int);
    163  1.11  macallan static int	crmfb_wait_dma_idle(struct crmfb_softc *);
    164   1.7  macallan 
    165   1.7  macallan /* setup video hw in given colour depth */
    166   1.7  macallan static int	crmfb_setup_video(struct crmfb_softc *, int);
    167   1.7  macallan static void	crmfb_setup_palette(struct crmfb_softc *);
    168   1.1  jmcneill 
    169  1.11  macallan #ifdef CRMFB_DEBUG
    170  1.11  macallan void crmfb_test_mte(struct crmfb_softc *);
    171  1.11  macallan #endif
    172  1.11  macallan 
    173  1.11  macallan static void crmfb_fill_rect(struct crmfb_softc *, int, int, int, int, uint32_t);
    174  1.11  macallan static void crmfb_bitblt(struct crmfb_softc *, int, int, int, int, int, int,
    175  1.11  macallan 			 uint32_t);
    176  1.15  macallan static void crmfb_scroll(struct crmfb_softc *, int, int, int, int, int, int);
    177  1.11  macallan 
    178  1.11  macallan static void	crmfb_copycols(void *, int, int, int, int);
    179  1.11  macallan static void	crmfb_erasecols(void *, int, int, int, long);
    180  1.11  macallan static void	crmfb_copyrows(void *, int, int, int);
    181  1.11  macallan static void	crmfb_eraserows(void *, int, int, long);
    182  1.11  macallan static void	crmfb_cursor(void *, int, int, int);
    183  1.11  macallan static void	crmfb_putchar(void *, int, int, u_int, long);
    184  1.11  macallan 
    185  1.29  macallan CFATTACH_DECL_NEW(crmfb, sizeof(struct crmfb_softc),
    186   1.1  jmcneill     crmfb_match, crmfb_attach, NULL, NULL);
    187   1.1  jmcneill 
    188   1.1  jmcneill static int
    189  1.29  macallan crmfb_match(device_t parent, struct cfdata *cf, void *opaque)
    190   1.1  jmcneill {
    191   1.1  jmcneill 	return crmfb_probe();
    192   1.1  jmcneill }
    193   1.1  jmcneill 
    194   1.1  jmcneill static void
    195  1.29  macallan crmfb_attach(device_t parent, device_t self, void *opaque)
    196   1.1  jmcneill {
    197   1.1  jmcneill 	struct mainbus_attach_args *ma;
    198   1.1  jmcneill 	struct crmfb_softc *sc;
    199   1.1  jmcneill 	struct rasops_info *ri;
    200   1.1  jmcneill 	struct wsemuldisplaydev_attach_args aa;
    201   1.1  jmcneill 	uint32_t d, h;
    202   1.1  jmcneill 	uint16_t *p;
    203   1.1  jmcneill 	unsigned long v;
    204   1.1  jmcneill 	long defattr;
    205   1.2  jmcneill 	const char *consdev;
    206  1.11  macallan 	int rv, i;
    207   1.1  jmcneill 
    208  1.29  macallan 	sc = device_private(self);
    209  1.29  macallan 	sc->sc_dev = self;
    210  1.29  macallan 
    211   1.1  jmcneill 	ma = (struct mainbus_attach_args *)opaque;
    212   1.1  jmcneill 
    213   1.1  jmcneill 	sc->sc_iot = SGIMIPS_BUS_SPACE_CRIME;
    214   1.1  jmcneill 	sc->sc_dmat = &sgimips_default_bus_dma_tag;
    215   1.1  jmcneill 	sc->sc_wsmode = WSDISPLAYIO_MODE_EMUL;
    216   1.1  jmcneill 
    217   1.1  jmcneill 	aprint_normal(": SGI CRIME Graphics Display Engine\n");
    218   1.1  jmcneill 	rv = bus_space_map(sc->sc_iot, ma->ma_addr, 0 /* XXX */,
    219   1.1  jmcneill 	    BUS_SPACE_MAP_LINEAR, &sc->sc_ioh);
    220   1.1  jmcneill 	if (rv)
    221   1.1  jmcneill 		panic("crmfb_attach: can't map I/O space");
    222  1.11  macallan 	rv = bus_space_map(sc->sc_iot, 0x15000000, 0x6000, 0, &sc->sc_reh);
    223  1.11  macallan 	if (rv)
    224  1.11  macallan 		panic("crmfb_attach: can't map rendering engine");
    225   1.1  jmcneill 
    226   1.1  jmcneill 	/* determine mode configured by firmware */
    227   1.9  jmcneill 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_HCMAP);
    228   1.9  jmcneill 	sc->sc_width = (d >> CRMFB_VT_HCMAP_ON_SHIFT) & 0xfff;
    229   1.1  jmcneill 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_VCMAP);
    230   1.9  jmcneill 	sc->sc_height = (d >> CRMFB_VT_VCMAP_ON_SHIFT) & 0xfff;
    231   1.1  jmcneill 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE);
    232   1.1  jmcneill 	h = (d >> CRMFB_FRM_TILESIZE_DEPTH_SHIFT) & 0x3;
    233   1.1  jmcneill 	if (h == 0)
    234   1.1  jmcneill 		sc->sc_depth = 8;
    235   1.1  jmcneill 	else if (h == 1)
    236   1.1  jmcneill 		sc->sc_depth = 16;
    237   1.1  jmcneill 	else
    238   1.1  jmcneill 		sc->sc_depth = 32;
    239   1.1  jmcneill 
    240   1.4    martin 	if (sc->sc_width == 0 || sc->sc_height == 0) {
    241  1.29  macallan 		aprint_error_dev(sc->sc_dev,
    242  1.29  macallan 		    "device unusable if not setup by firmware\n");
    243   1.4    martin 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, 0 /* XXX */);
    244   1.4    martin 		return;
    245   1.4    martin 	}
    246   1.4    martin 
    247  1.29  macallan 	aprint_normal_dev(sc->sc_dev, "initial resolution %dx%d\n",
    248  1.29  macallan 	    sc->sc_width, sc->sc_height);
    249   1.1  jmcneill 
    250   1.7  macallan 	/*
    251   1.7  macallan 	 * first determine how many tiles we need
    252   1.7  macallan 	 * in 32bit each tile is 128x128 pixels
    253   1.7  macallan 	 */
    254  1.11  macallan 	sc->sc_tiles_x = (sc->sc_width + 127) >> 7;
    255  1.11  macallan 	sc->sc_tiles_y = (sc->sc_height + 127) >> 7;
    256  1.11  macallan 	sc->sc_fbsize = 0x10000 * sc->sc_tiles_x * sc->sc_tiles_y;
    257   1.1  jmcneill 
    258   1.7  macallan 	sc->sc_dmai.size = 256 * sizeof(uint16_t);
    259   1.1  jmcneill 	rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_dmai.size, 65536, 0,
    260   1.1  jmcneill 	    sc->sc_dmai.segs,
    261   1.1  jmcneill 	    sizeof(sc->sc_dmai.segs) / sizeof(sc->sc_dmai.segs[0]),
    262   1.1  jmcneill 	    &sc->sc_dmai.nsegs, BUS_DMA_NOWAIT);
    263   1.1  jmcneill 	if (rv)
    264   1.1  jmcneill 		panic("crmfb_attach: can't allocate DMA memory");
    265   1.1  jmcneill 	rv = bus_dmamem_map(sc->sc_dmat, sc->sc_dmai.segs, sc->sc_dmai.nsegs,
    266   1.1  jmcneill 	    sc->sc_dmai.size, &sc->sc_dmai.addr,
    267   1.1  jmcneill 	    BUS_DMA_NOWAIT);
    268   1.1  jmcneill 	if (rv)
    269   1.1  jmcneill 		panic("crmfb_attach: can't map DMA memory");
    270   1.1  jmcneill 	rv = bus_dmamap_create(sc->sc_dmat, sc->sc_dmai.size, 1,
    271   1.1  jmcneill 	    sc->sc_dmai.size, 0, BUS_DMA_NOWAIT, &sc->sc_dmai.map);
    272   1.1  jmcneill 	if (rv)
    273   1.1  jmcneill 		panic("crmfb_attach: can't create DMA map");
    274   1.1  jmcneill 	rv = bus_dmamap_load(sc->sc_dmat, sc->sc_dmai.map, sc->sc_dmai.addr,
    275   1.1  jmcneill 	    sc->sc_dmai.size, NULL, BUS_DMA_NOWAIT);
    276   1.1  jmcneill 	if (rv)
    277   1.1  jmcneill 		panic("crmfb_attach: can't load DMA map");
    278   1.1  jmcneill 
    279  1.21  macallan 	/* allocate an extra 64Kb for a linear buffer */
    280  1.21  macallan 	sc->sc_dma.size = 0x10000 * (16 * sc->sc_tiles_x + 1);
    281   1.1  jmcneill 	rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_dma.size, 65536, 0,
    282   1.1  jmcneill 	    sc->sc_dma.segs,
    283   1.1  jmcneill 	    sizeof(sc->sc_dma.segs) / sizeof(sc->sc_dma.segs[0]),
    284   1.1  jmcneill 	    &sc->sc_dma.nsegs, BUS_DMA_NOWAIT);
    285   1.1  jmcneill 	if (rv)
    286   1.1  jmcneill 		panic("crmfb_attach: can't allocate DMA memory");
    287   1.1  jmcneill 	rv = bus_dmamem_map(sc->sc_dmat, sc->sc_dma.segs, sc->sc_dma.nsegs,
    288   1.1  jmcneill 	    sc->sc_dma.size, &sc->sc_dma.addr,
    289   1.1  jmcneill 	    BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
    290   1.1  jmcneill 	if (rv)
    291   1.1  jmcneill 		panic("crmfb_attach: can't map DMA memory");
    292   1.1  jmcneill 	rv = bus_dmamap_create(sc->sc_dmat, sc->sc_dma.size, 1,
    293   1.1  jmcneill 	    sc->sc_dma.size, 0, BUS_DMA_NOWAIT, &sc->sc_dma.map);
    294   1.1  jmcneill 	if (rv)
    295   1.1  jmcneill 		panic("crmfb_attach: can't create DMA map");
    296   1.1  jmcneill 	rv = bus_dmamap_load(sc->sc_dmat, sc->sc_dma.map, sc->sc_dma.addr,
    297   1.1  jmcneill 	    sc->sc_dma.size, NULL, BUS_DMA_NOWAIT);
    298   1.1  jmcneill 	if (rv)
    299   1.1  jmcneill 		panic("crmfb_attach: can't load DMA map");
    300   1.1  jmcneill 
    301   1.1  jmcneill 	p = KERNADDR(sc->sc_dmai);
    302   1.1  jmcneill 	v = (unsigned long)DMAADDR(sc->sc_dma);
    303  1.11  macallan 	for (i = 0; i < (sc->sc_tiles_x * sc->sc_tiles_y); i++) {
    304   1.1  jmcneill 		p[i] = ((uint32_t)v >> 16) + i;
    305   1.1  jmcneill 	}
    306  1.26   tsutsui 	bus_dmamap_sync(sc->sc_dmat, sc->sc_dmai.map, 0, sc->sc_dmai.size,
    307  1.26   tsutsui 	    BUS_DMASYNC_PREWRITE);
    308  1.21  macallan 	sc->sc_scratch = (char *)KERNADDR(sc->sc_dma) + (0xf0000 * sc->sc_tiles_x);
    309  1.21  macallan 	sc->sc_linear = (paddr_t)DMAADDR(sc->sc_dma) + 0x100000 * sc->sc_tiles_x;
    310   1.1  jmcneill 
    311  1.29  macallan 	aprint_normal_dev(sc->sc_dev, "allocated %d byte fb @ %p (%p)\n",
    312   1.1  jmcneill 	    sc->sc_fbsize, KERNADDR(sc->sc_dmai), KERNADDR(sc->sc_dma));
    313   1.1  jmcneill 
    314  1.21  macallan 	crmfb_setup_video(sc, 8);
    315   1.1  jmcneill 	ri = &crmfb_console_screen.scr_ri;
    316   1.1  jmcneill 	memset(ri, 0, sizeof(struct rasops_info));
    317   1.1  jmcneill 
    318   1.1  jmcneill 	vcons_init(&sc->sc_vd, sc, &crmfb_defaultscreen, &crmfb_accessops);
    319   1.1  jmcneill 	sc->sc_vd.init_screen = crmfb_init_screen;
    320   1.1  jmcneill 	crmfb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    321   1.1  jmcneill 	vcons_init_screen(&sc->sc_vd, &crmfb_console_screen, 1, &defattr);
    322   1.1  jmcneill 
    323   1.1  jmcneill 	crmfb_defaultscreen.ncols = ri->ri_cols;
    324   1.1  jmcneill 	crmfb_defaultscreen.nrows = ri->ri_rows;
    325   1.1  jmcneill 	crmfb_defaultscreen.textops = &ri->ri_ops;
    326   1.1  jmcneill 	crmfb_defaultscreen.capabilities = ri->ri_caps;
    327   1.1  jmcneill 	crmfb_defaultscreen.modecookie = NULL;
    328   1.1  jmcneill 
    329   1.7  macallan 	crmfb_setup_palette(sc);
    330  1.14  macallan 	crmfb_fill_rect(sc, 0, 0, sc->sc_width, sc->sc_height,
    331  1.17  macallan 	    ri->ri_devcmap[(defattr >> 16) & 0xff]);
    332   1.1  jmcneill 
    333  1.27      matt 	consdev = arcbios_GetEnvironmentVariable("ConsoleOut");
    334   1.2  jmcneill 	if (consdev != NULL && strcmp(consdev, "video()") == 0) {
    335   1.2  jmcneill 		wsdisplay_cnattach(&crmfb_defaultscreen, ri, 0, 0, defattr);
    336  1.28  macallan 		vcons_replay_msgbuf(&crmfb_console_screen);
    337   1.2  jmcneill 		aa.console = 1;
    338   1.2  jmcneill 	} else
    339   1.2  jmcneill 		aa.console = 0;
    340   1.1  jmcneill 	aa.scrdata = &crmfb_screenlist;
    341   1.1  jmcneill 	aa.accessops = &crmfb_accessops;
    342   1.1  jmcneill 	aa.accesscookie = &sc->sc_vd;
    343   1.1  jmcneill 
    344   1.1  jmcneill 	config_found(self, &aa, wsemuldisplaydevprint);
    345   1.1  jmcneill 
    346   1.6  macallan 	sc->sc_cur_x = 0;
    347   1.6  macallan 	sc->sc_cur_y = 0;
    348   1.6  macallan 	sc->sc_hot_x = 0;
    349   1.6  macallan 	sc->sc_hot_y = 0;
    350   1.6  macallan 
    351  1.11  macallan #ifdef CRMFB_DEBUG
    352  1.11  macallan 	crmfb_test_mte(sc);
    353  1.11  macallan #endif
    354   1.1  jmcneill 	return;
    355   1.1  jmcneill }
    356   1.1  jmcneill 
    357   1.1  jmcneill int
    358   1.1  jmcneill crmfb_probe(void)
    359   1.1  jmcneill {
    360   1.1  jmcneill 
    361   1.1  jmcneill         if (mach_type != MACH_SGI_IP32)
    362   1.1  jmcneill                 return 0;
    363   1.1  jmcneill 
    364   1.1  jmcneill 	return 1;
    365   1.1  jmcneill }
    366   1.1  jmcneill 
    367   1.1  jmcneill static int
    368   1.1  jmcneill crmfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    369   1.1  jmcneill {
    370   1.1  jmcneill 	struct vcons_data *vd;
    371   1.1  jmcneill 	struct crmfb_softc *sc;
    372   1.1  jmcneill 	struct vcons_screen *ms;
    373   1.1  jmcneill 	struct wsdisplay_fbinfo *wdf;
    374   1.1  jmcneill 	int nmode;
    375   1.1  jmcneill 
    376   1.1  jmcneill 	vd = (struct vcons_data *)v;
    377   1.1  jmcneill 	sc = (struct crmfb_softc *)vd->cookie;
    378   1.1  jmcneill 	ms = (struct vcons_screen *)vd->active;
    379   1.1  jmcneill 
    380   1.1  jmcneill 	switch (cmd) {
    381   1.1  jmcneill 	case WSDISPLAYIO_GTYPE:
    382   1.1  jmcneill 		/* not really, but who cares? */
    383   1.7  macallan 		/* wsfb does */
    384   1.7  macallan 		*(u_int *)data = WSDISPLAY_TYPE_CRIME;
    385   1.1  jmcneill 		return 0;
    386   1.1  jmcneill 	case WSDISPLAYIO_GINFO:
    387   1.1  jmcneill 		if (vd->active != NULL) {
    388   1.1  jmcneill 			wdf = (void *)data;
    389   1.1  jmcneill 			wdf->height = sc->sc_height;
    390   1.1  jmcneill 			wdf->width = sc->sc_width;
    391   1.7  macallan 			wdf->depth = 32;
    392   1.1  jmcneill 			wdf->cmsize = 256;
    393   1.1  jmcneill 			return 0;
    394   1.1  jmcneill 		} else
    395   1.1  jmcneill 			return ENODEV;
    396   1.1  jmcneill 	case WSDISPLAYIO_GETCMAP:
    397   1.1  jmcneill 		if (sc->sc_depth == 8)
    398   1.1  jmcneill 			return crmfb_getcmap(sc, (struct wsdisplay_cmap *)data);
    399   1.1  jmcneill 		else
    400   1.1  jmcneill 			return EINVAL;
    401   1.1  jmcneill 	case WSDISPLAYIO_PUTCMAP:
    402   1.1  jmcneill 		if (sc->sc_depth == 8)
    403   1.1  jmcneill 			return crmfb_putcmap(sc, (struct wsdisplay_cmap *)data);
    404   1.1  jmcneill 		else
    405   1.1  jmcneill 			return EINVAL;
    406   1.1  jmcneill 	case WSDISPLAYIO_LINEBYTES:
    407   1.1  jmcneill 		*(u_int *)data = sc->sc_width * sc->sc_depth / 8;
    408   1.1  jmcneill 		return 0;
    409   1.1  jmcneill 	case WSDISPLAYIO_SMODE:
    410   1.1  jmcneill 		nmode = *(int *)data;
    411   1.1  jmcneill 		if (nmode != sc->sc_wsmode) {
    412   1.1  jmcneill 			sc->sc_wsmode = nmode;
    413   1.7  macallan 			if (nmode == WSDISPLAYIO_MODE_EMUL) {
    414   1.7  macallan 				crmfb_setup_video(sc, 8);
    415   1.7  macallan 				crmfb_setup_palette(sc);
    416   1.1  jmcneill 				vcons_redraw_screen(vd->active);
    417   1.7  macallan 			} else {
    418   1.7  macallan 				crmfb_setup_video(sc, 32);
    419   1.7  macallan 			}
    420   1.1  jmcneill 		}
    421   1.1  jmcneill 		return 0;
    422   1.5  jmcneill 	case WSDISPLAYIO_SVIDEO:
    423   1.5  jmcneill 	case WSDISPLAYIO_GVIDEO:
    424   1.5  jmcneill 		return ENODEV;	/* not supported yet */
    425   1.6  macallan 
    426   1.6  macallan 	case WSDISPLAYIO_GCURPOS:
    427   1.6  macallan 		{
    428   1.6  macallan 			struct wsdisplay_curpos *pos;
    429   1.6  macallan 
    430   1.6  macallan 			pos = (struct wsdisplay_curpos *)data;
    431   1.6  macallan 			pos->x = sc->sc_cur_x;
    432   1.6  macallan 			pos->y = sc->sc_cur_y;
    433   1.6  macallan 		}
    434   1.6  macallan 		return 0;
    435   1.6  macallan 	case WSDISPLAYIO_SCURPOS:
    436   1.6  macallan 		{
    437   1.6  macallan 			struct wsdisplay_curpos *pos;
    438   1.6  macallan 
    439   1.6  macallan 			pos = (struct wsdisplay_curpos *)data;
    440   1.6  macallan 			crmfb_set_curpos(sc, pos->x, pos->y);
    441   1.6  macallan 		}
    442   1.6  macallan 		return 0;
    443   1.6  macallan 	case WSDISPLAYIO_GCURMAX:
    444   1.6  macallan 		{
    445   1.6  macallan 			struct wsdisplay_curpos *pos;
    446   1.6  macallan 
    447   1.6  macallan 			pos = (struct wsdisplay_curpos *)data;
    448   1.6  macallan 			pos->x = 32;
    449   1.6  macallan 			pos->y = 32;
    450   1.6  macallan 		}
    451   1.6  macallan 		return 0;
    452   1.6  macallan 	case WSDISPLAYIO_GCURSOR:
    453   1.6  macallan 		{
    454   1.6  macallan 			struct wsdisplay_cursor *cu;
    455   1.6  macallan 
    456   1.6  macallan 			cu = (struct wsdisplay_cursor *)data;
    457   1.6  macallan 			return crmfb_gcursor(sc, cu);
    458   1.6  macallan 		}
    459   1.6  macallan 	case WSDISPLAYIO_SCURSOR:
    460   1.6  macallan 		{
    461   1.6  macallan 			struct wsdisplay_cursor *cu;
    462   1.6  macallan 
    463   1.6  macallan 			cu = (struct wsdisplay_cursor *)data;
    464   1.6  macallan 			return crmfb_scursor(sc, cu);
    465   1.6  macallan 		}
    466   1.1  jmcneill 	}
    467   1.1  jmcneill 	return EPASSTHROUGH;
    468   1.1  jmcneill }
    469   1.1  jmcneill 
    470   1.1  jmcneill static paddr_t
    471   1.1  jmcneill crmfb_mmap(void *v, void *vs, off_t offset, int prot)
    472   1.1  jmcneill {
    473   1.1  jmcneill 	struct vcons_data *vd;
    474   1.1  jmcneill 	struct crmfb_softc *sc;
    475   1.1  jmcneill 	paddr_t pa;
    476   1.1  jmcneill 
    477   1.1  jmcneill 	vd = (struct vcons_data *)v;
    478   1.1  jmcneill 	sc = (struct crmfb_softc *)vd->cookie;
    479   1.1  jmcneill 
    480  1.14  macallan 	/* we probably shouldn't let anyone mmap the framebuffer */
    481   1.7  macallan #if 1
    482  1.22  macallan 	if (offset >= 0 && offset < (0x100000 * sc->sc_tiles_x)) {
    483   1.1  jmcneill 		pa = bus_dmamem_mmap(sc->sc_dmat, sc->sc_dma.segs,
    484   1.1  jmcneill 		    sc->sc_dma.nsegs, offset, prot,
    485   1.3  jmcneill 		    BUS_DMA_WAITOK | BUS_DMA_COHERENT);
    486   1.1  jmcneill 		return pa;
    487   1.1  jmcneill 	}
    488   1.7  macallan #endif
    489  1.14  macallan 	/*
    490  1.14  macallan 	 * here would the TLBs be but we don't want to show them to userland
    491  1.14  macallan 	 * so we return the page containing the status register
    492  1.14  macallan 	 */
    493  1.14  macallan 	if ((offset >= 0x15000000) && (offset < 0x15002000))
    494  1.14  macallan 		return bus_space_mmap(sc->sc_iot, 0x15004000, 0, prot, 0);
    495  1.14  macallan 	/* now the actual engine registers */
    496  1.14  macallan 	if ((offset >= 0x15002000) && (offset < 0x15005000))
    497  1.14  macallan 		return bus_space_mmap(sc->sc_iot, offset, 0, prot, 0);
    498  1.14  macallan 	/* and now the scratch area */
    499  1.14  macallan 	if ((offset >= 0x15010000) && (offset < 0x15020000))
    500  1.14  macallan 		return bus_dmamem_mmap(sc->sc_dmat, sc->sc_dma.segs,
    501  1.21  macallan 		     sc->sc_dma.nsegs,
    502  1.21  macallan 		     offset + (0x100000 * sc->sc_tiles_x) - 0x15010000,
    503  1.21  macallan 		     prot, BUS_DMA_WAITOK | BUS_DMA_COHERENT);
    504   1.1  jmcneill 	return -1;
    505   1.1  jmcneill }
    506   1.1  jmcneill 
    507   1.1  jmcneill static void
    508   1.1  jmcneill crmfb_init_screen(void *c, struct vcons_screen *scr, int existing,
    509   1.1  jmcneill     long *defattr)
    510   1.1  jmcneill {
    511   1.1  jmcneill 	struct crmfb_softc *sc;
    512   1.1  jmcneill 	struct rasops_info *ri;
    513   1.1  jmcneill 
    514   1.1  jmcneill 	sc = (struct crmfb_softc *)c;
    515   1.1  jmcneill 	ri = &scr->scr_ri;
    516   1.1  jmcneill 
    517  1.11  macallan 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
    518   1.1  jmcneill 	ri->ri_depth = sc->sc_depth;
    519   1.1  jmcneill 	ri->ri_width = sc->sc_width;
    520   1.1  jmcneill 	ri->ri_height = sc->sc_height;
    521   1.1  jmcneill 	ri->ri_stride = ri->ri_width * (ri->ri_depth / 8);
    522   1.1  jmcneill 
    523   1.1  jmcneill 	switch (ri->ri_depth) {
    524   1.1  jmcneill 	case 16:
    525   1.1  jmcneill 		ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 5;
    526   1.1  jmcneill 		ri->ri_rpos = 10;
    527   1.1  jmcneill 		ri->ri_gpos = 5;
    528   1.1  jmcneill 		ri->ri_bpos = 0;
    529   1.1  jmcneill 		break;
    530   1.1  jmcneill 	case 32:
    531   1.1  jmcneill 		ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 8;
    532   1.1  jmcneill 		ri->ri_rpos = 8;
    533   1.1  jmcneill 		ri->ri_gpos = 16;
    534   1.1  jmcneill 		ri->ri_bpos = 24;
    535   1.1  jmcneill 		break;
    536   1.1  jmcneill 	}
    537   1.1  jmcneill 
    538  1.11  macallan 	ri->ri_bits = KERNADDR(sc->sc_dma);
    539   1.1  jmcneill 
    540   1.1  jmcneill 	if (existing)
    541   1.1  jmcneill 		ri->ri_flg |= RI_CLEAR;
    542   1.1  jmcneill 
    543   1.1  jmcneill 	rasops_init(ri, ri->ri_height / 16, ri->ri_width / 8);
    544   1.1  jmcneill 	ri->ri_caps = WSSCREEN_WSCOLORS;
    545   1.1  jmcneill 	rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
    546   1.1  jmcneill 	    ri->ri_width / ri->ri_font->fontwidth);
    547   1.1  jmcneill 	ri->ri_hw = scr;
    548   1.1  jmcneill 
    549  1.11  macallan 	ri->ri_ops.cursor    = crmfb_cursor;
    550  1.11  macallan 	ri->ri_ops.copyrows  = crmfb_copyrows;
    551  1.11  macallan 	ri->ri_ops.eraserows = crmfb_eraserows;
    552  1.11  macallan 	ri->ri_ops.copycols  = crmfb_copycols;
    553  1.11  macallan 	ri->ri_ops.erasecols = crmfb_erasecols;
    554  1.11  macallan 	ri->ri_ops.putchar   = crmfb_putchar;
    555  1.11  macallan 
    556   1.1  jmcneill 	return;
    557   1.1  jmcneill }
    558   1.1  jmcneill 
    559   1.1  jmcneill static int
    560   1.1  jmcneill crmfb_putcmap(struct crmfb_softc *sc, struct wsdisplay_cmap *cm)
    561   1.1  jmcneill {
    562   1.1  jmcneill 	u_int idx, cnt;
    563   1.1  jmcneill 	u_char r[256], g[256], b[256];
    564   1.1  jmcneill 	u_char *rp, *gp, *bp;
    565   1.1  jmcneill 	int rv, i;
    566   1.1  jmcneill 
    567   1.1  jmcneill 	idx = cm->index;
    568   1.1  jmcneill 	cnt = cm->count;
    569   1.1  jmcneill 
    570   1.1  jmcneill 	if (idx >= 255 || cnt > 256 || idx + cnt > 256)
    571   1.1  jmcneill 		return EINVAL;
    572   1.1  jmcneill 
    573   1.1  jmcneill 	rv = copyin(cm->red, &r[idx], cnt);
    574   1.1  jmcneill 	if (rv)
    575   1.1  jmcneill 		return rv;
    576   1.1  jmcneill 	rv = copyin(cm->green, &g[idx], cnt);
    577   1.1  jmcneill 	if (rv)
    578   1.1  jmcneill 		return rv;
    579   1.1  jmcneill 	rv = copyin(cm->blue, &b[idx], cnt);
    580   1.1  jmcneill 	if (rv)
    581   1.1  jmcneill 		return rv;
    582   1.1  jmcneill 
    583   1.1  jmcneill 	memcpy(&sc->sc_cmap_red[idx], &r[idx], cnt);
    584   1.1  jmcneill 	memcpy(&sc->sc_cmap_green[idx], &g[idx], cnt);
    585   1.1  jmcneill 	memcpy(&sc->sc_cmap_blue[idx], &b[idx], cnt);
    586   1.1  jmcneill 
    587   1.1  jmcneill 	rp = &sc->sc_cmap_red[idx];
    588   1.1  jmcneill 	gp = &sc->sc_cmap_green[idx];
    589   1.1  jmcneill 	bp = &sc->sc_cmap_blue[idx];
    590   1.1  jmcneill 
    591   1.1  jmcneill 	for (i = 0; i < cnt; i++) {
    592   1.1  jmcneill 		crmfb_set_palette(sc, idx, *rp, *gp, *bp);
    593   1.1  jmcneill 		idx++;
    594   1.1  jmcneill 		rp++, gp++, bp++;
    595   1.1  jmcneill 	}
    596   1.1  jmcneill 
    597   1.1  jmcneill 	return 0;
    598   1.1  jmcneill }
    599   1.1  jmcneill 
    600   1.1  jmcneill static int
    601   1.1  jmcneill crmfb_getcmap(struct crmfb_softc *sc, struct wsdisplay_cmap *cm)
    602   1.1  jmcneill {
    603   1.1  jmcneill 	u_int idx, cnt;
    604   1.1  jmcneill 	int rv;
    605   1.1  jmcneill 
    606   1.1  jmcneill 	idx = cm->index;
    607   1.1  jmcneill 	cnt = cm->count;
    608   1.1  jmcneill 
    609   1.1  jmcneill 	if (idx >= 255 || cnt > 256 || idx + cnt > 256)
    610   1.1  jmcneill 		return EINVAL;
    611   1.1  jmcneill 
    612   1.1  jmcneill 	rv = copyout(&sc->sc_cmap_red[idx], cm->red, cnt);
    613   1.1  jmcneill 	if (rv)
    614   1.1  jmcneill 		return rv;
    615   1.1  jmcneill 	rv = copyout(&sc->sc_cmap_green[idx], cm->green, cnt);
    616   1.1  jmcneill 	if (rv)
    617   1.1  jmcneill 		return rv;
    618   1.1  jmcneill 	rv = copyout(&sc->sc_cmap_blue[idx], cm->blue, cnt);
    619   1.1  jmcneill 	if (rv)
    620   1.1  jmcneill 		return rv;
    621   1.1  jmcneill 
    622   1.1  jmcneill 	return 0;
    623   1.1  jmcneill }
    624   1.1  jmcneill 
    625   1.1  jmcneill static void
    626   1.1  jmcneill crmfb_set_palette(struct crmfb_softc *sc, int reg, uint8_t r, uint8_t g,
    627   1.1  jmcneill     uint8_t b)
    628   1.1  jmcneill {
    629   1.1  jmcneill 	uint32_t val;
    630   1.1  jmcneill 
    631   1.1  jmcneill 	if (reg > 255 || sc->sc_depth != 8)
    632   1.1  jmcneill 		return;
    633   1.1  jmcneill 
    634   1.1  jmcneill 	while (bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_CMAP_FIFO) >= 63)
    635   1.1  jmcneill 		DELAY(10);
    636   1.1  jmcneill 
    637  1.23  jmcneill 	val = (r << 8) | (g << 16) | (b << 24);
    638   1.7  macallan 	crmfb_write_reg(sc, CRMFB_CMAP + (reg * 4), val);
    639   1.1  jmcneill 
    640   1.1  jmcneill 	return;
    641   1.1  jmcneill }
    642   1.6  macallan 
    643   1.6  macallan static int
    644   1.6  macallan crmfb_set_curpos(struct crmfb_softc *sc, int x, int y)
    645   1.6  macallan {
    646   1.6  macallan 	uint32_t val;
    647   1.6  macallan 
    648   1.6  macallan 	sc->sc_cur_x = x;
    649   1.6  macallan 	sc->sc_cur_y = y;
    650   1.6  macallan 
    651   1.6  macallan 	val = ((x - sc->sc_hot_x) & 0xffff) | ((y - sc->sc_hot_y) << 16);
    652   1.7  macallan 	crmfb_write_reg(sc, CRMFB_CURSOR_POS, val);
    653   1.6  macallan 
    654   1.6  macallan 	return 0;
    655   1.6  macallan }
    656   1.6  macallan 
    657   1.6  macallan static int
    658   1.6  macallan crmfb_gcursor(struct crmfb_softc *sc, struct wsdisplay_cursor *cur)
    659   1.6  macallan {
    660   1.6  macallan 	/* do nothing for now */
    661   1.6  macallan 	return 0;
    662   1.6  macallan }
    663   1.6  macallan 
    664   1.6  macallan static int
    665   1.6  macallan crmfb_scursor(struct crmfb_softc *sc, struct wsdisplay_cursor *cur)
    666   1.6  macallan {
    667   1.6  macallan 	if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
    668   1.6  macallan 
    669   1.7  macallan 		crmfb_write_reg(sc, CRMFB_CURSOR_CONTROL, cur->enable ? 1 : 0);
    670   1.6  macallan 	}
    671   1.6  macallan 	if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
    672   1.6  macallan 
    673   1.6  macallan 		sc->sc_hot_x = cur->hot.x;
    674   1.6  macallan 		sc->sc_hot_y = cur->hot.y;
    675   1.6  macallan 	}
    676   1.6  macallan 	if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
    677   1.6  macallan 
    678   1.6  macallan 		crmfb_set_curpos(sc, cur->pos.x, cur->pos.y);
    679   1.6  macallan 	}
    680   1.6  macallan 	if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
    681   1.6  macallan 		int i;
    682   1.6  macallan 		uint32_t val;
    683   1.6  macallan 
    684   1.6  macallan 		for (i = 0; i < cur->cmap.count; i++) {
    685   1.6  macallan 			val = (cur->cmap.red[i] << 24) |
    686   1.6  macallan 			      (cur->cmap.green[i] << 16) |
    687   1.6  macallan 			      (cur->cmap.blue[i] << 8);
    688   1.7  macallan 			crmfb_write_reg(sc, CRMFB_CURSOR_CMAP0 +
    689   1.7  macallan 			    ((i + cur->cmap.index) << 2), val);
    690   1.6  macallan 		}
    691   1.6  macallan 	}
    692   1.6  macallan 	if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
    693   1.6  macallan 
    694   1.6  macallan 		int i, j, cnt = 0;
    695   1.6  macallan 		uint32_t latch = 0, omask;
    696   1.6  macallan 		uint8_t imask;
    697   1.6  macallan 		for (i = 0; i < 64; i++) {
    698   1.6  macallan 			omask = 0x80000000;
    699   1.6  macallan 			imask = 0x01;
    700   1.6  macallan 			cur->image[cnt] &= cur->mask[cnt];
    701   1.6  macallan 			for (j = 0; j < 8; j++) {
    702   1.6  macallan 				if (cur->image[cnt] & imask)
    703   1.6  macallan 					latch |= omask;
    704   1.6  macallan 				omask >>= 1;
    705   1.6  macallan 				if (cur->mask[cnt] & imask)
    706   1.6  macallan 					latch |= omask;
    707   1.6  macallan 				omask >>= 1;
    708   1.6  macallan 				imask <<= 1;
    709   1.6  macallan 			}
    710   1.6  macallan 			cnt++;
    711   1.6  macallan 			imask = 0x01;
    712   1.6  macallan 			cur->image[cnt] &= cur->mask[cnt];
    713   1.6  macallan 			for (j = 0; j < 8; j++) {
    714   1.6  macallan 				if (cur->image[cnt] & imask)
    715   1.6  macallan 					latch |= omask;
    716   1.6  macallan 				omask >>= 1;
    717   1.6  macallan 				if (cur->mask[cnt] & imask)
    718   1.6  macallan 					latch |= omask;
    719   1.6  macallan 				omask >>= 1;
    720   1.6  macallan 				imask <<= 1;
    721   1.6  macallan 			}
    722   1.6  macallan 			cnt++;
    723   1.7  macallan 			crmfb_write_reg(sc, CRMFB_CURSOR_BITMAP + (i << 2),
    724   1.7  macallan 			    latch);
    725   1.6  macallan 			latch = 0;
    726   1.6  macallan 		}
    727   1.6  macallan 	}
    728   1.6  macallan 	return 0;
    729   1.6  macallan }
    730   1.7  macallan 
    731   1.7  macallan static inline void
    732   1.7  macallan crmfb_write_reg(struct crmfb_softc *sc, int offset, uint32_t val)
    733   1.7  macallan {
    734   1.7  macallan 
    735   1.7  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, offset, val);
    736   1.7  macallan 	wbflush();
    737   1.7  macallan }
    738   1.7  macallan 
    739  1.11  macallan static inline uint32_t
    740  1.11  macallan crmfb_read_reg(struct crmfb_softc *sc, int offset)
    741  1.11  macallan {
    742  1.11  macallan 
    743  1.11  macallan 	return bus_space_read_4(sc->sc_iot, sc->sc_ioh, offset);
    744  1.11  macallan }
    745  1.11  macallan 
    746  1.11  macallan static int
    747  1.11  macallan crmfb_wait_dma_idle(struct crmfb_softc *sc)
    748  1.11  macallan {
    749  1.11  macallan 	int bail = 100000, idle;
    750  1.11  macallan 
    751  1.11  macallan 	do {
    752  1.11  macallan 		idle = ((bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    753  1.11  macallan 		         CRMFB_OVR_CONTROL) & 1) == 0) &&
    754  1.11  macallan 		       ((bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    755  1.11  macallan 		         CRMFB_FRM_CONTROL) & 1) == 0) &&
    756  1.11  macallan 		       ((bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    757  1.11  macallan 		         CRMFB_DID_CONTROL) & 1) == 0);
    758  1.11  macallan 		if (!idle)
    759  1.11  macallan 			delay(10);
    760  1.11  macallan 		bail--;
    761  1.11  macallan 	} while ((!idle) && (bail > 0));
    762  1.11  macallan 	return idle;
    763  1.11  macallan }
    764  1.11  macallan 
    765   1.7  macallan static int
    766   1.7  macallan crmfb_setup_video(struct crmfb_softc *sc, int depth)
    767   1.7  macallan {
    768  1.11  macallan 	uint64_t reg;
    769  1.21  macallan 	uint32_t d, h, mode, page;
    770  1.21  macallan 	int i, bail, tile_width, tlbptr, lptr, j, tx, shift;
    771  1.10    sekiya 	const char *wantsync;
    772  1.11  macallan 	uint16_t v;
    773  1.11  macallan 
    774   1.7  macallan 	/* disable DMA */
    775   1.7  macallan 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_OVR_CONTROL);
    776   1.7  macallan 	d &= ~(1 << CRMFB_OVR_CONTROL_DMAEN_SHIFT);
    777   1.7  macallan 	crmfb_write_reg(sc, CRMFB_OVR_CONTROL, d);
    778   1.7  macallan 	DELAY(50000);
    779   1.7  macallan 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL);
    780   1.7  macallan 	d &= ~(1 << CRMFB_FRM_CONTROL_DMAEN_SHIFT);
    781   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_CONTROL, d);
    782   1.7  macallan 	DELAY(50000);
    783   1.7  macallan 	crmfb_write_reg(sc, CRMFB_DID_CONTROL, 0);
    784   1.7  macallan 	DELAY(50000);
    785   1.7  macallan 
    786  1.11  macallan 	if (!crmfb_wait_dma_idle(sc))
    787  1.11  macallan 		aprint_error("crmfb: crmfb_wait_dma_idle timed out\n");
    788  1.11  macallan 
    789   1.7  macallan 	/* ensure that CRM starts drawing at the top left of the screen
    790   1.7  macallan 	 * when we re-enable DMA later
    791   1.7  macallan 	 */
    792   1.7  macallan 	d = (1 << CRMFB_VT_XY_FREEZE_SHIFT);
    793   1.7  macallan 	crmfb_write_reg(sc, CRMFB_VT_XY, d);
    794   1.7  macallan 	delay(1000);
    795   1.7  macallan 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK);
    796   1.7  macallan 	d &= ~(1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT);
    797   1.7  macallan 	crmfb_write_reg(sc, CRMFB_DOTCLOCK, d);
    798  1.11  macallan 
    799  1.11  macallan 	/* wait for dotclock to turn off */
    800  1.11  macallan 	bail = 10000;
    801  1.11  macallan 	while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK) &
    802  1.11  macallan 	    (1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT)) && (bail > 0)) {
    803  1.11  macallan 		delay(10);
    804  1.11  macallan 		bail--;
    805  1.11  macallan 	}
    806   1.7  macallan 
    807   1.7  macallan 	/* reset FIFO */
    808   1.7  macallan 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE);
    809   1.7  macallan 	d |= (1 << CRMFB_FRM_TILESIZE_FIFOR_SHIFT);
    810   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_TILESIZE, d);
    811   1.7  macallan 	d &= ~(1 << CRMFB_FRM_TILESIZE_FIFOR_SHIFT);
    812   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_TILESIZE, d);
    813   1.7  macallan 
    814   1.7  macallan 	/* setup colour mode */
    815   1.7  macallan 	switch (depth) {
    816   1.7  macallan 	case 8:
    817   1.7  macallan 		h = CRMFB_MODE_TYP_I8;
    818  1.11  macallan 		tile_width = 512;
    819   1.7  macallan 		break;
    820   1.7  macallan 	case 16:
    821   1.7  macallan 		h = CRMFB_MODE_TYP_ARGB5;
    822  1.11  macallan 		tile_width = 256;
    823   1.7  macallan 		break;
    824   1.7  macallan 	case 32:
    825   1.7  macallan 		h = CRMFB_MODE_TYP_RGB8;
    826  1.11  macallan 		tile_width = 128;
    827   1.7  macallan 		break;
    828   1.7  macallan 	default:
    829   1.7  macallan 		panic("Unsupported depth");
    830   1.7  macallan 	}
    831   1.7  macallan 	d = h << CRMFB_MODE_TYP_SHIFT;
    832   1.7  macallan 	d |= CRMFB_MODE_BUF_BOTH << CRMFB_MODE_BUF_SHIFT;
    833   1.7  macallan 	for (i = 0; i < (32 * 4); i += 4)
    834   1.7  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_MODE + i, d);
    835   1.7  macallan 	wbflush();
    836   1.7  macallan 
    837   1.7  macallan 	/* setup tile pointer, but don't turn on DMA yet! */
    838   1.7  macallan 	h = DMAADDR(sc->sc_dmai);
    839   1.7  macallan 	d = (h >> 9) << CRMFB_FRM_CONTROL_TILEPTR_SHIFT;
    840   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_CONTROL, d);
    841   1.7  macallan 
    842   1.7  macallan 	/* init framebuffer width and pixel size */
    843  1.11  macallan 	/*d = (1 << CRMFB_FRM_TILESIZE_WIDTH_SHIFT);*/
    844  1.11  macallan 
    845  1.11  macallan 	d = ((int)(sc->sc_width / tile_width)) <<
    846  1.11  macallan 	    CRMFB_FRM_TILESIZE_WIDTH_SHIFT;
    847  1.11  macallan 	if ((sc->sc_width & (tile_width - 1)) != 0)
    848  1.11  macallan 		d |= sc->sc_tiles_y;
    849  1.11  macallan 
    850   1.7  macallan 	switch (depth) {
    851   1.7  macallan 	case 8:
    852   1.7  macallan 		h = CRMFB_FRM_TILESIZE_DEPTH_8;
    853   1.7  macallan 		break;
    854   1.7  macallan 	case 16:
    855   1.7  macallan 		h = CRMFB_FRM_TILESIZE_DEPTH_16;
    856   1.7  macallan 		break;
    857   1.7  macallan 	case 32:
    858   1.7  macallan 		h = CRMFB_FRM_TILESIZE_DEPTH_32;
    859   1.7  macallan 		break;
    860   1.7  macallan 	default:
    861   1.7  macallan 		panic("Unsupported depth");
    862   1.7  macallan 	}
    863   1.7  macallan 	d |= (h << CRMFB_FRM_TILESIZE_DEPTH_SHIFT);
    864   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_TILESIZE, d);
    865   1.7  macallan 
    866  1.11  macallan 	/*h = sc->sc_width * sc->sc_height / (512 / (depth >> 3));*/
    867  1.11  macallan 	h = sc->sc_height;
    868   1.7  macallan 	d = h << CRMFB_FRM_PIXSIZE_HEIGHT_SHIFT;
    869   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_PIXSIZE, d);
    870   1.7  macallan 
    871   1.7  macallan 	/* turn off firmware overlay and hardware cursor */
    872   1.7  macallan 	crmfb_write_reg(sc, CRMFB_OVR_WIDTH_TILE, 0);
    873   1.7  macallan 	crmfb_write_reg(sc, CRMFB_CURSOR_CONTROL, 0);
    874   1.7  macallan 
    875   1.7  macallan 	/* enable drawing again */
    876   1.7  macallan 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK);
    877   1.7  macallan 	d |= (1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT);
    878   1.7  macallan 	crmfb_write_reg(sc, CRMFB_DOTCLOCK, d);
    879   1.7  macallan 	crmfb_write_reg(sc, CRMFB_VT_XY, 0);
    880   1.7  macallan 
    881   1.7  macallan 	/* turn on DMA for the framebuffer */
    882   1.7  macallan 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL);
    883   1.7  macallan 	d |= (1 << CRMFB_FRM_CONTROL_DMAEN_SHIFT);
    884   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_CONTROL, d);
    885   1.7  macallan 
    886  1.10    sekiya 	/* turn off sync-on-green */
    887  1.10    sekiya 
    888  1.27      matt 	wantsync = arcbios_GetEnvironmentVariable("SyncOnGreen");
    889  1.10    sekiya 	if ( (wantsync != NULL) && (wantsync[0] == 'n') ) {
    890  1.15  macallan 		d = ( 1 << CRMFB_VT_FLAGS_SYNC_LOW_LSB) &
    891  1.15  macallan 		    CRMFB_REG_MASK(CRMFB_VT_FLAGS_SYNC_LOW_MSB,
    892  1.15  macallan 		    CRMFB_VT_FLAGS_SYNC_LOW_LSB);
    893  1.10    sekiya 		crmfb_write_reg(sc, CRMFB_VT_FLAGS, d);
    894  1.10    sekiya 	}
    895  1.10    sekiya 
    896   1.7  macallan 	sc->sc_depth = depth;
    897  1.11  macallan 
    898  1.11  macallan 	/* finally set up the drawing engine's TLB A */
    899  1.11  macallan 	v = (DMAADDR(sc->sc_dma) >> 16) & 0xffff;
    900  1.11  macallan 	tlbptr = 0;
    901  1.15  macallan 	tx = ((sc->sc_width + (tile_width - 1)) & ~(tile_width - 1)) /
    902  1.15  macallan 	    tile_width;
    903  1.14  macallan 
    904  1.21  macallan #ifdef CRMFB_DEBUG
    905  1.21  macallan 	printf("tx: %d\n", tx);
    906  1.21  macallan #endif
    907  1.21  macallan 
    908  1.21  macallan 	for (i = 0; i < 16; i++) {
    909  1.11  macallan 		reg = 0;
    910  1.11  macallan 		shift = 64;
    911  1.21  macallan 		lptr = 0;
    912  1.11  macallan 		for (j = 0; j < tx; j++) {
    913  1.11  macallan 			shift -= 16;
    914  1.11  macallan 			reg |= (((uint64_t)(v | 0x8000)) << shift);
    915  1.11  macallan 			if (shift == 0) {
    916  1.11  macallan 				shift = 64;
    917  1.11  macallan 				bus_space_write_8(sc->sc_iot, sc->sc_reh,
    918  1.21  macallan 				    CRIME_RE_TLB_A + tlbptr + lptr,
    919  1.15  macallan 				    reg);
    920  1.21  macallan #ifdef CRMFB_DEBUG
    921  1.21  macallan 				printf("%04x: %016llx\n", tlbptr + lptr, reg);
    922  1.21  macallan #endif
    923  1.21  macallan 				reg = 0;
    924  1.21  macallan 				lptr += 8;
    925  1.11  macallan 			}
    926  1.11  macallan 			v++;
    927  1.11  macallan 		}
    928  1.11  macallan 		if (shift != 64) {
    929  1.11  macallan 			bus_space_write_8(sc->sc_iot, sc->sc_reh,
    930  1.21  macallan 			    CRIME_RE_TLB_A + tlbptr + lptr, reg);
    931  1.21  macallan #ifdef CRMFB_DEBUG
    932  1.21  macallan 			printf("%04x: %016llx\n", tlbptr + lptr, reg);
    933  1.21  macallan #endif
    934  1.11  macallan 		}
    935  1.11  macallan 		tlbptr += 32;
    936  1.11  macallan 	}
    937  1.21  macallan 	sc->sc_scratch = (char *)KERNADDR(sc->sc_dma) + (0xf0000 * tx);
    938  1.11  macallan 
    939  1.21  macallan 	/* now put the last 64kB into the 1st linear TLB */
    940  1.21  macallan 	page = (sc->sc_linear >> 12) | 0x80000000;
    941  1.21  macallan 	tlbptr = 0;
    942  1.21  macallan 	for (i = 0; i < 8; i++) {
    943  1.21  macallan 		reg = ((uint64_t)page << 32) | (page + 1);
    944  1.21  macallan 		bus_space_write_8(sc->sc_iot, sc->sc_reh,
    945  1.21  macallan 		    CRIME_RE_LINEAR_A + tlbptr, reg);
    946  1.21  macallan 		page += 2;
    947  1.21  macallan 		tlbptr += 8;
    948  1.21  macallan 	}
    949  1.11  macallan 	wbflush();
    950  1.11  macallan 
    951  1.11  macallan 	/* do some very basic engine setup */
    952  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_CLIPMODE, 0);
    953  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_WINOFFSET_SRC, 0);
    954  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_WINOFFSET_DST, 0);
    955  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_PLANEMASK,
    956  1.15  macallan 	    0xffffffff);
    957  1.11  macallan 
    958  1.11  macallan 	bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x20, 0);
    959  1.11  macallan 	bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x28, 0);
    960  1.11  macallan 	bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x30, 0);
    961  1.11  macallan 	bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x38, 0);
    962  1.11  macallan 	bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x40, 0);
    963  1.11  macallan 
    964  1.11  macallan 	switch (depth) {
    965  1.11  macallan 		case 8:
    966  1.11  macallan 			mode = DE_MODE_TLB_A | DE_MODE_BUFDEPTH_8 |
    967  1.11  macallan 			    DE_MODE_TYPE_CI | DE_MODE_PIXDEPTH_8;
    968  1.11  macallan 			break;
    969  1.11  macallan 		case 16:
    970  1.11  macallan 			mode = DE_MODE_TLB_A | DE_MODE_BUFDEPTH_16 |
    971  1.11  macallan 			    DE_MODE_TYPE_RGB | DE_MODE_PIXDEPTH_16;
    972  1.14  macallan 			break;
    973  1.11  macallan 		case 32:
    974  1.11  macallan 			mode = DE_MODE_TLB_A | DE_MODE_BUFDEPTH_32 |
    975  1.11  macallan 			    DE_MODE_TYPE_RGBA | DE_MODE_PIXDEPTH_32;
    976  1.14  macallan 			break;
    977  1.11  macallan 		default:
    978  1.11  macallan 			panic("%s: unsuported colour depth %d\n", __func__,
    979  1.11  macallan 			    depth);
    980  1.11  macallan 	}
    981  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_MODE_DST, mode);
    982  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_MODE_SRC, mode);
    983  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_XFER_STEP_X, 1);
    984  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_XFER_STEP_Y, 1);
    985  1.15  macallan 
    986  1.15  macallan 	/* initialize memory transfer engine */
    987  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_MODE,
    988  1.15  macallan 	    MTE_MODE_DST_ECC |
    989  1.15  macallan 	    (MTE_TLB_A << MTE_DST_TLB_SHIFT) |
    990  1.15  macallan 	    (MTE_TLB_A << MTE_SRC_TLB_SHIFT) |
    991  1.15  macallan 	    (MTE_DEPTH_8 << MTE_DEPTH_SHIFT) |
    992  1.15  macallan 	    MTE_MODE_COPY);
    993  1.18  macallan 	sc->sc_mte_direction = 1;
    994  1.16  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST_Y_STEP, 1);
    995  1.16  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC_Y_STEP, 1);
    996  1.15  macallan 
    997   1.7  macallan 	return 0;
    998   1.7  macallan }
    999   1.7  macallan 
   1000  1.19  macallan static void
   1001  1.18  macallan crmfb_set_mte_direction(struct crmfb_softc *sc, int dir)
   1002  1.18  macallan {
   1003  1.18  macallan 	if (dir == sc->sc_mte_direction)
   1004  1.18  macallan 		return;
   1005  1.18  macallan 
   1006  1.18  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST_Y_STEP, dir);
   1007  1.18  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC_Y_STEP, dir);
   1008  1.20  macallan 	sc->sc_mte_direction = dir;
   1009  1.18  macallan }
   1010  1.18  macallan 
   1011   1.7  macallan static void
   1012   1.7  macallan crmfb_setup_palette(struct crmfb_softc *sc)
   1013   1.7  macallan {
   1014   1.7  macallan 	int i;
   1015   1.7  macallan 
   1016   1.7  macallan 	for (i = 0; i < 256; i++) {
   1017   1.7  macallan 		crmfb_set_palette(sc, i, rasops_cmap[(i * 3) + 2],
   1018   1.7  macallan 		    rasops_cmap[(i * 3) + 1], rasops_cmap[(i * 3) + 0]);
   1019   1.7  macallan 		sc->sc_cmap_red[i] = rasops_cmap[(i * 3) + 2];
   1020   1.7  macallan 		sc->sc_cmap_green[i] = rasops_cmap[(i * 3) + 1];
   1021   1.7  macallan 		sc->sc_cmap_blue[i] = rasops_cmap[(i * 3) + 0];
   1022   1.7  macallan 	}
   1023   1.7  macallan }
   1024  1.11  macallan 
   1025  1.11  macallan static inline void
   1026  1.11  macallan crmfb_wait_idle(struct crmfb_softc *sc)
   1027  1.11  macallan {
   1028  1.11  macallan 	int i = 0;
   1029  1.11  macallan 
   1030  1.11  macallan 	do {
   1031  1.11  macallan 		i++;
   1032  1.11  macallan 	} while (((bus_space_read_4(sc->sc_iot, sc->sc_reh, CRIME_DE_STATUS) &
   1033  1.11  macallan 		   CRIME_DE_IDLE) == 0) && (i < 100000000));
   1034  1.11  macallan 	if (i >= 100000000)
   1035  1.11  macallan 		aprint_error("crmfb_wait_idle() timed out\n");
   1036  1.11  macallan }
   1037  1.11  macallan 
   1038  1.11  macallan static void
   1039  1.11  macallan crmfb_fill_rect(struct crmfb_softc *sc, int x, int y, int width, int height,
   1040  1.11  macallan     uint32_t colour)
   1041  1.11  macallan {
   1042  1.11  macallan 	crmfb_wait_idle(sc);
   1043  1.18  macallan 	crmfb_set_mte_direction(sc, 1);
   1044  1.17  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_MODE,
   1045  1.17  macallan 	    MTE_MODE_DST_ECC |
   1046  1.17  macallan 	    (MTE_TLB_A << MTE_DST_TLB_SHIFT) |
   1047  1.17  macallan 	    (MTE_TLB_A << MTE_SRC_TLB_SHIFT) |
   1048  1.17  macallan 	    (MTE_DEPTH_8 << MTE_DEPTH_SHIFT) |
   1049  1.17  macallan 	    0);
   1050  1.17  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_BG, colour);
   1051  1.17  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST0,
   1052  1.11  macallan 	    (x << 16) | (y & 0xffff));
   1053  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1054  1.17  macallan 	    CRIME_MTE_DST1 | CRIME_DE_START,
   1055  1.11  macallan 	    ((x + width - 1) << 16) | ((y + height - 1) & 0xffff));
   1056  1.11  macallan }
   1057  1.11  macallan 
   1058  1.11  macallan static void
   1059  1.11  macallan crmfb_bitblt(struct crmfb_softc *sc, int xs, int ys, int xd, int yd,
   1060  1.11  macallan     int wi, int he, uint32_t rop)
   1061  1.11  macallan {
   1062  1.11  macallan 	uint32_t prim = DE_PRIM_RECTANGLE;
   1063  1.11  macallan 	int rxa, rya, rxe, rye, rxs, rys;
   1064  1.11  macallan 	crmfb_wait_idle(sc);
   1065  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_DRAWMODE,
   1066  1.11  macallan 	    DE_DRAWMODE_PLANEMASK | DE_DRAWMODE_BYTEMASK | DE_DRAWMODE_ROP |
   1067  1.11  macallan 	    DE_DRAWMODE_XFER_EN);
   1068  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_ROP, rop);
   1069  1.11  macallan 	if (xs < xd) {
   1070  1.11  macallan 		prim |= DE_PRIM_RL;
   1071  1.11  macallan 		rxe = xd;
   1072  1.11  macallan 		rxa = xd + wi - 1;
   1073  1.11  macallan 		rxs = xs + wi - 1;
   1074  1.11  macallan 	} else {
   1075  1.11  macallan 		prim |= DE_PRIM_LR;
   1076  1.11  macallan 		rxe = xd + wi - 1;
   1077  1.11  macallan 		rxa = xd;
   1078  1.11  macallan 		rxs = xs;
   1079  1.11  macallan 	}
   1080  1.11  macallan 	if (ys < yd) {
   1081  1.11  macallan 		prim |= DE_PRIM_BT;
   1082  1.11  macallan 		rye = yd;
   1083  1.11  macallan 		rya = yd + he - 1;
   1084  1.11  macallan 		rys = ys + he - 1;
   1085  1.11  macallan 	} else {
   1086  1.11  macallan 		prim |= DE_PRIM_TB;
   1087  1.11  macallan 		rye = yd + he - 1;
   1088  1.11  macallan 		rya = yd;
   1089  1.11  macallan 		rys = ys;
   1090  1.11  macallan 	}
   1091  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_PRIMITIVE, prim);
   1092  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_XFER_ADDR_SRC,
   1093  1.11  macallan 	    (rxs << 16) | (rys & 0xffff));
   1094  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_X_VERTEX_0,
   1095  1.11  macallan 	    (rxa << 16) | (rya & 0xffff));
   1096  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1097  1.11  macallan 	    CRIME_DE_X_VERTEX_1 | CRIME_DE_START,
   1098  1.11  macallan 	    (rxe << 16) | (rye & 0xffff));
   1099  1.11  macallan }
   1100  1.11  macallan 
   1101  1.15  macallan static void
   1102  1.15  macallan crmfb_scroll(struct crmfb_softc *sc, int xs, int ys, int xd, int yd,
   1103  1.15  macallan     int wi, int he)
   1104  1.15  macallan {
   1105  1.15  macallan 	int rxa, rya, rxe, rye, rxd, ryd, rxde, ryde;
   1106  1.15  macallan 
   1107  1.16  macallan 	rxa = xs;
   1108  1.16  macallan 	rxe = xs + wi - 1;
   1109  1.16  macallan 	rxd = xd;
   1110  1.16  macallan 	rxde = xd + wi - 1;
   1111  1.16  macallan 
   1112  1.15  macallan 	crmfb_wait_idle(sc);
   1113  1.16  macallan 
   1114  1.17  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_MODE,
   1115  1.17  macallan 	    MTE_MODE_DST_ECC |
   1116  1.17  macallan 	    (MTE_TLB_A << MTE_DST_TLB_SHIFT) |
   1117  1.17  macallan 	    (MTE_TLB_A << MTE_SRC_TLB_SHIFT) |
   1118  1.17  macallan 	    (MTE_DEPTH_8 << MTE_DEPTH_SHIFT) |
   1119  1.17  macallan 	    MTE_MODE_COPY);
   1120  1.17  macallan 
   1121  1.15  macallan 	if (ys < yd) {
   1122  1.15  macallan 		/* bottom to top */
   1123  1.15  macallan 		rye = ys;
   1124  1.15  macallan 		rya = ys + he - 1;
   1125  1.15  macallan 		ryd = yd + he - 1;
   1126  1.15  macallan 		ryde = yd;
   1127  1.18  macallan 		crmfb_set_mte_direction(sc, -1);
   1128  1.15  macallan 	} else {
   1129  1.15  macallan 		/* top to bottom */
   1130  1.15  macallan 		rye = ys + he - 1;
   1131  1.15  macallan 		rya = ys;
   1132  1.15  macallan 		ryd = yd;
   1133  1.15  macallan 		ryde = yd + he - 1;
   1134  1.18  macallan 		crmfb_set_mte_direction(sc, 1);
   1135  1.15  macallan 	}
   1136  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC0,
   1137  1.15  macallan 	    (rxa << 16) | rya);
   1138  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC1,
   1139  1.15  macallan 	    (rxe << 16) | rye);
   1140  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1141  1.15  macallan 	    CRIME_MTE_DST0,
   1142  1.15  macallan 	    (rxd << 16) | ryd);
   1143  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST1 |
   1144  1.15  macallan 	    CRIME_DE_START,
   1145  1.15  macallan 	    (rxde << 16) | ryde);
   1146  1.15  macallan }
   1147  1.15  macallan 
   1148  1.11  macallan #ifdef CRMFB_DEBUG
   1149  1.11  macallan void
   1150  1.11  macallan crmfb_test_mte(struct crmfb_softc *sc)
   1151  1.11  macallan {
   1152  1.15  macallan 	uint64_t addr, reg;
   1153  1.15  macallan 	uint32_t addrs[256];
   1154  1.15  macallan 	int i, j, boo;
   1155  1.11  macallan 
   1156  1.15  macallan 	crmfb_wait_idle(sc);
   1157  1.15  macallan 	addr = (uint64_t)(DMAADDR(sc->sc_dma) + sc->sc_fbsize);
   1158  1.15  macallan 	addr = addr >> 12;
   1159  1.15  macallan 	for (i = 0; i < 64; i += 8) {
   1160  1.15  macallan #if 1
   1161  1.15  macallan 		reg = (addr << 32) | (addr + 1) | 0x8000000080000000LL;
   1162  1.15  macallan 		bus_space_write_8(sc->sc_iot, sc->sc_reh,
   1163  1.15  macallan 		    CRIME_RE_LINEAR_A + i, reg);
   1164  1.15  macallan 		printf(" %08x", (uint32_t)(addr & 0xffffffff));
   1165  1.15  macallan #endif
   1166  1.15  macallan 		addr += 2;
   1167  1.15  macallan 	}
   1168  1.15  macallan 	printf("\n");
   1169  1.15  macallan 	memset(sc->sc_scratch, 4, 0x10000);
   1170  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_MODE_SRC,
   1171  1.15  macallan 	    DE_MODE_LIN_A | DE_MODE_BUFDEPTH_8 | DE_MODE_TYPE_CI |
   1172  1.15  macallan 	    DE_MODE_PIXDEPTH_8);
   1173  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_XFER_STRD_SRC, 1);
   1174  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_DRAWMODE,
   1175  1.15  macallan 	    DE_DRAWMODE_PLANEMASK | DE_DRAWMODE_BYTEMASK | DE_DRAWMODE_ROP |
   1176  1.15  macallan 	    DE_DRAWMODE_XFER_EN);
   1177  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_ROP, 3);
   1178  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_PRIMITIVE,
   1179  1.15  macallan 	    DE_PRIM_RECTANGLE | DE_PRIM_TB);
   1180  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_XFER_ADDR_SRC, 0);
   1181  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_X_VERTEX_0,
   1182  1.15  macallan 	    0x02000000);
   1183  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1184  1.15  macallan 	    CRIME_DE_X_VERTEX_1 | CRIME_DE_START,
   1185  1.15  macallan 	    0x04000100);
   1186  1.11  macallan 
   1187  1.11  macallan 	crmfb_wait_idle(sc);
   1188  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_MODE_SRC,
   1189  1.15  macallan 	    DE_MODE_TLB_A | DE_MODE_BUFDEPTH_8 | DE_MODE_TYPE_CI |
   1190  1.15  macallan 	    DE_MODE_PIXDEPTH_8);
   1191  1.15  macallan 
   1192  1.15  macallan #if 1
   1193  1.11  macallan 	delay(4000000);
   1194  1.11  macallan 
   1195  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_BG, 0x15151515);
   1196  1.15  macallan 	crmfb_wait_idle(sc);
   1197  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_MODE,
   1198  1.11  macallan 	    MTE_MODE_DST_ECC |
   1199  1.15  macallan 	    (MTE_TLB_LIN_A << MTE_DST_TLB_SHIFT) |
   1200  1.11  macallan 	    (MTE_TLB_A << MTE_SRC_TLB_SHIFT) |
   1201  1.11  macallan 	    (MTE_DEPTH_8 << MTE_DEPTH_SHIFT) |
   1202  1.11  macallan 	    0/*MTE_MODE_COPY*/);
   1203  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST_STRIDE, 1);
   1204  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC_STRIDE, 1);
   1205  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC0, 0x00000000);
   1206  1.15  macallan 	//bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC1, 0x01000100);
   1207  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST0, 0x00000000);
   1208  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST1 |
   1209  1.15  macallan 	    CRIME_DE_START, 0x00010000);
   1210  1.15  macallan 	//status[9] = bus_space_read_4(sc->sc_iot, sc->sc_reh, CRIME_DE_STATUS);
   1211  1.15  macallan 	crmfb_wait_idle(sc);
   1212  1.15  macallan 	/* now look for 0x05050505 in RAM */
   1213  1.15  macallan 
   1214  1.15  macallan 	boo = 0;
   1215  1.15  macallan 	for (i = 0xA0000000; i < 0xB0000000; i += 0x1000)
   1216  1.15  macallan 		if (*((uint32_t *)i) == 0x15151515) {
   1217  1.15  macallan 			/* see if there's more */
   1218  1.15  macallan 			j = 4;
   1219  1.15  macallan 			while ((j < 0x100) && (*((uint32_t *)(i + j)) ==
   1220  1.15  macallan 			    0x15151515))
   1221  1.15  macallan 				j += 4;
   1222  1.15  macallan 			if (j > 0x20) {
   1223  1.15  macallan 				addrs[boo] = i;
   1224  1.15  macallan 				boo++;
   1225  1.15  macallan 			}
   1226  1.15  macallan 		}
   1227  1.15  macallan 	printf("...");
   1228  1.15  macallan 	for (i = 0; i < boo; i++)
   1229  1.15  macallan 		printf(" %08x", addrs[i]);
   1230  1.15  macallan 	printf("\n");
   1231  1.11  macallan #endif
   1232  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_MODE_SRC,
   1233  1.15  macallan 	    DE_MODE_LIN_A | DE_MODE_BUFDEPTH_8 | DE_MODE_TYPE_CI |
   1234  1.15  macallan 	    DE_MODE_PIXDEPTH_8);
   1235  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_XFER_STRD_SRC, 1);
   1236  1.15  macallan 	crmfb_bitblt(sc, 0, 0, 400, 0, 512, 64, 3);
   1237  1.15  macallan 	crmfb_wait_idle(sc);
   1238  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_MODE_SRC,
   1239  1.15  macallan 	    DE_MODE_TLB_A | DE_MODE_BUFDEPTH_8 | DE_MODE_TYPE_CI |
   1240  1.15  macallan 	    DE_MODE_PIXDEPTH_8);
   1241  1.15  macallan #if 0
   1242  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_MODE,
   1243  1.11  macallan 	    MTE_MODE_DST_ECC |
   1244  1.11  macallan 	    (MTE_TLB_A << MTE_DST_TLB_SHIFT) |
   1245  1.11  macallan 	    (MTE_TLB_A << MTE_SRC_TLB_SHIFT) |
   1246  1.11  macallan 	    (MTE_DEPTH_8 << MTE_DEPTH_SHIFT) |
   1247  1.11  macallan 	    0/*MTE_MODE_COPY*/);
   1248  1.11  macallan #endif
   1249  1.11  macallan 	delay(4000000);
   1250  1.11  macallan #if 0
   1251  1.15  macallan 	for (i = 0; i < 128; i+=8)
   1252  1.15  macallan 		printf("%016llx\n", bus_space_read_8(sc->sc_iot, sc->sc_reh,
   1253  1.15  macallan 		    CRIME_RE_LINEAR_B + i));
   1254  1.15  macallan #endif
   1255  1.15  macallan #if 0
   1256  1.11  macallan 	printf("flush: %08x\n",
   1257  1.11  macallan 	    bus_space_read_4(sc->sc_iot, sc->sc_reh, CRIME_DE_FLUSH));
   1258  1.11  macallan #endif
   1259  1.11  macallan }
   1260  1.11  macallan #endif /* CRMFB_DEBUG */
   1261  1.11  macallan 
   1262  1.11  macallan static void
   1263  1.11  macallan crmfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
   1264  1.11  macallan {
   1265  1.11  macallan 	struct rasops_info *ri = cookie;
   1266  1.11  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1267  1.11  macallan 	int32_t xs, xd, y, width, height;
   1268  1.11  macallan 
   1269  1.11  macallan 	xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
   1270  1.11  macallan 	xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
   1271  1.11  macallan 	y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1272  1.11  macallan 	width = ri->ri_font->fontwidth * ncols;
   1273  1.11  macallan 	height = ri->ri_font->fontheight;
   1274  1.11  macallan 	crmfb_bitblt(scr->scr_cookie, xs, y, xd, y, width, height, 3);
   1275  1.11  macallan }
   1276  1.11  macallan 
   1277  1.11  macallan static void
   1278  1.11  macallan crmfb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
   1279  1.11  macallan {
   1280  1.11  macallan 	struct rasops_info *ri = cookie;
   1281  1.11  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1282  1.11  macallan 	int32_t x, y, width, height, bg;
   1283  1.11  macallan 
   1284  1.11  macallan 	x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
   1285  1.11  macallan 	y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1286  1.11  macallan 	width = ri->ri_font->fontwidth * ncols;
   1287  1.11  macallan 	height = ri->ri_font->fontheight;
   1288  1.11  macallan 	bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
   1289  1.11  macallan 	crmfb_fill_rect(scr->scr_cookie, x, y, width, height, bg);
   1290  1.11  macallan }
   1291  1.11  macallan 
   1292  1.11  macallan static void
   1293  1.11  macallan crmfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
   1294  1.11  macallan {
   1295  1.11  macallan 	struct rasops_info *ri = cookie;
   1296  1.11  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1297  1.11  macallan 	int32_t x, ys, yd, width, height;
   1298  1.11  macallan 
   1299  1.11  macallan 	x = ri->ri_xorigin;
   1300  1.11  macallan 	ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
   1301  1.11  macallan 	yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
   1302  1.11  macallan 	width = ri->ri_emuwidth;
   1303  1.11  macallan 	height = ri->ri_font->fontheight * nrows;
   1304  1.15  macallan 
   1305  1.16  macallan 	crmfb_scroll(scr->scr_cookie, x, ys, x, yd, width, height);
   1306  1.11  macallan }
   1307  1.11  macallan 
   1308  1.11  macallan static void
   1309  1.11  macallan crmfb_eraserows(void *cookie, int row, int nrows, long fillattr)
   1310  1.11  macallan {
   1311  1.11  macallan 	struct rasops_info *ri = cookie;
   1312  1.11  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1313  1.11  macallan 	int32_t x, y, width, height, bg;
   1314  1.11  macallan 
   1315  1.11  macallan 	if ((row == 0) && (nrows == ri->ri_rows)) {
   1316  1.11  macallan 		x = y = 0;
   1317  1.11  macallan 		width = ri->ri_width;
   1318  1.11  macallan 		height = ri->ri_height;
   1319  1.11  macallan 	} else {
   1320  1.11  macallan 		x = ri->ri_xorigin;
   1321  1.11  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1322  1.11  macallan 		width = ri->ri_emuwidth;
   1323  1.11  macallan 		height = ri->ri_font->fontheight * nrows;
   1324  1.11  macallan 	}
   1325  1.11  macallan 	bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
   1326  1.11  macallan 	crmfb_fill_rect(scr->scr_cookie, x, y, width, height, bg);
   1327  1.11  macallan }
   1328  1.11  macallan 
   1329  1.11  macallan static void
   1330  1.11  macallan crmfb_cursor(void *cookie, int on, int row, int col)
   1331  1.11  macallan {
   1332  1.11  macallan 	struct rasops_info *ri = cookie;
   1333  1.11  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1334  1.11  macallan 	struct crmfb_softc *sc = scr->scr_cookie;
   1335  1.11  macallan 	int x, y, wi,he;
   1336  1.11  macallan 
   1337  1.11  macallan 	wi = ri->ri_font->fontwidth;
   1338  1.11  macallan 	he = ri->ri_font->fontheight;
   1339  1.11  macallan 
   1340  1.11  macallan 	if (ri->ri_flg & RI_CURSOR) {
   1341  1.11  macallan 		x = ri->ri_ccol * wi + ri->ri_xorigin;
   1342  1.11  macallan 		y = ri->ri_crow * he + ri->ri_yorigin;
   1343  1.11  macallan 		crmfb_bitblt(sc, x, y, x, y, wi, he, 12);
   1344  1.11  macallan 		ri->ri_flg &= ~RI_CURSOR;
   1345  1.11  macallan 	}
   1346  1.11  macallan 
   1347  1.11  macallan 	ri->ri_crow = row;
   1348  1.11  macallan 	ri->ri_ccol = col;
   1349  1.11  macallan 
   1350  1.11  macallan 	if (on)
   1351  1.11  macallan 	{
   1352  1.11  macallan 		x = ri->ri_ccol * wi + ri->ri_xorigin;
   1353  1.11  macallan 		y = ri->ri_crow * he + ri->ri_yorigin;
   1354  1.11  macallan 		crmfb_bitblt(sc, x, y, x, y, wi, he, 12);
   1355  1.11  macallan 		ri->ri_flg |= RI_CURSOR;
   1356  1.11  macallan 	}
   1357  1.11  macallan }
   1358  1.11  macallan 
   1359  1.11  macallan static void
   1360  1.11  macallan crmfb_putchar(void *cookie, int row, int col, u_int c, long attr)
   1361  1.11  macallan {
   1362  1.11  macallan 	struct rasops_info *ri = cookie;
   1363  1.11  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1364  1.11  macallan 	struct crmfb_softc *sc = scr->scr_cookie;
   1365  1.28  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, c);
   1366  1.28  macallan 	uint32_t bg, fg;
   1367  1.28  macallan 	int x, y, wi, he, i, uc;
   1368  1.28  macallan 	uint8_t *fd8;
   1369  1.28  macallan 	uint16_t *fd16;
   1370  1.28  macallan 	void *fd;
   1371  1.11  macallan 
   1372  1.28  macallan 	wi = font->fontwidth;
   1373  1.28  macallan 	he = font->fontheight;
   1374  1.11  macallan 
   1375  1.11  macallan 	x = ri->ri_xorigin + col * wi;
   1376  1.11  macallan 	y = ri->ri_yorigin + row * he;
   1377  1.11  macallan 
   1378  1.17  macallan 	bg = ri->ri_devcmap[(attr >> 16) & 0xff];
   1379  1.28  macallan 	fg = ri->ri_devcmap[(attr >> 24) & 0xff];
   1380  1.28  macallan 	uc = c - font->firstchar;
   1381  1.28  macallan 	fd = (uint8_t *)font->data + uc * ri->ri_fontscale;
   1382  1.11  macallan 	if (c == 0x20) {
   1383  1.11  macallan 		crmfb_fill_rect(sc, x, y, wi, he, bg);
   1384  1.11  macallan 	} else {
   1385  1.28  macallan 		crmfb_wait_idle(sc);
   1386  1.28  macallan 		/* setup */
   1387  1.28  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_ROP, 3);
   1388  1.28  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_FG, fg);
   1389  1.28  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_BG, bg);
   1390  1.28  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_DRAWMODE,
   1391  1.28  macallan 		    DE_DRAWMODE_PLANEMASK | DE_DRAWMODE_BYTEMASK |
   1392  1.28  macallan 		    DE_DRAWMODE_ROP |
   1393  1.28  macallan 		    DE_DRAWMODE_OPAQUE_STIP | DE_DRAWMODE_POLY_STIP);
   1394  1.28  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_PRIMITIVE,
   1395  1.28  macallan 		    DE_PRIM_RECTANGLE | DE_PRIM_LR | DE_PRIM_TB);
   1396  1.28  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_STIPPLE_MODE,
   1397  1.28  macallan 		    0x001f0000);
   1398  1.28  macallan 		/* now let's feed the engine */
   1399  1.28  macallan 		if (font->stride == 1) {
   1400  1.28  macallan 			/* shovel in 8 bit quantities */
   1401  1.28  macallan 			fd8 = fd;
   1402  1.28  macallan 			for (i = 0; i < he; i++) {
   1403  1.28  macallan 				/*
   1404  1.28  macallan 				 * the pipeline should be long enough to
   1405  1.28  macallan 				 * draw any character without having to wait
   1406  1.28  macallan 				 */
   1407  1.28  macallan 				bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1408  1.28  macallan 				    CRIME_DE_STIPPLE_PAT, *fd8 << 24);
   1409  1.28  macallan 				bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1410  1.28  macallan 				    CRIME_DE_X_VERTEX_0, (x << 16) | y);
   1411  1.28  macallan 				bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1412  1.28  macallan 				    CRIME_DE_X_VERTEX_1 | CRIME_DE_START,
   1413  1.28  macallan 				    ((x + wi) << 16) | y);
   1414  1.28  macallan 				y++;
   1415  1.28  macallan 				fd8++;
   1416  1.28  macallan 			}
   1417  1.28  macallan 		} else if (font->stride == 2) {
   1418  1.28  macallan 			/* shovel in 16 bit quantities */
   1419  1.28  macallan 			fd16 = fd;
   1420  1.28  macallan 			for (i = 0; i < he; i++) {
   1421  1.28  macallan 				/*
   1422  1.28  macallan 				 * the pipeline should be long enough to
   1423  1.28  macallan 				 * draw any character without having to wait
   1424  1.28  macallan 				 */
   1425  1.28  macallan 				bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1426  1.28  macallan 				    CRIME_DE_STIPPLE_PAT, *fd16 << 16);
   1427  1.28  macallan 				bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1428  1.28  macallan 				    CRIME_DE_X_VERTEX_0, (x << 16) | y);
   1429  1.28  macallan 				bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1430  1.28  macallan 				    CRIME_DE_X_VERTEX_1 | CRIME_DE_START,
   1431  1.28  macallan 				    ((x + wi) << 16) | y);
   1432  1.28  macallan 				y++;
   1433  1.28  macallan 				fd16++;
   1434  1.28  macallan 			}
   1435  1.28  macallan 		}
   1436  1.11  macallan 	}
   1437  1.11  macallan }
   1438