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