Home | History | Annotate | Line # | Download | only in ic
igsfb.c revision 1.1
      1  1.1  uwe /*	$NetBSD: igsfb.c,v 1.1 2002/03/30 19:48:55 uwe Exp $ */
      2  1.1  uwe 
      3  1.1  uwe /*
      4  1.1  uwe  * Copyright (c) 2002 Valeriy E. Ushakov
      5  1.1  uwe  * All rights reserved.
      6  1.1  uwe  *
      7  1.1  uwe  * Redistribution and use in source and binary forms, with or without
      8  1.1  uwe  * modification, are permitted provided that the following conditions
      9  1.1  uwe  * are met:
     10  1.1  uwe  * 1. Redistributions of source code must retain the above copyright
     11  1.1  uwe  *    notice, this list of conditions and the following disclaimer.
     12  1.1  uwe  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  uwe  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  uwe  *    documentation and/or other materials provided with the distribution.
     15  1.1  uwe  * 3. The name of the author may not be used to endorse or promote products
     16  1.1  uwe  *    derived from this software without specific prior written permission
     17  1.1  uwe  *
     18  1.1  uwe  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1  uwe  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1  uwe  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1  uwe  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1  uwe  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.1  uwe  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.1  uwe  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.1  uwe  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.1  uwe  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.1  uwe  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1  uwe  */
     29  1.1  uwe 
     30  1.1  uwe /*
     31  1.1  uwe  * Integraphics Systems IGA 1682 and (untested) CyberPro 2k.
     32  1.1  uwe  */
     33  1.1  uwe #include <sys/cdefs.h>
     34  1.1  uwe __KERNEL_RCSID(0, "$NetBSD: igsfb.c,v 1.1 2002/03/30 19:48:55 uwe Exp $");
     35  1.1  uwe 
     36  1.1  uwe #include <sys/param.h>
     37  1.1  uwe #include <sys/systm.h>
     38  1.1  uwe #include <sys/kernel.h>
     39  1.1  uwe #include <sys/device.h>
     40  1.1  uwe #include <sys/malloc.h>
     41  1.1  uwe #include <sys/buf.h>
     42  1.1  uwe #include <sys/ioctl.h>
     43  1.1  uwe 
     44  1.1  uwe #include <machine/autoconf.h>
     45  1.1  uwe #include <machine/bus.h>
     46  1.1  uwe #include <machine/intr.h>
     47  1.1  uwe 
     48  1.1  uwe #include <dev/wscons/wsconsio.h>
     49  1.1  uwe #include <dev/wscons/wsdisplayvar.h>
     50  1.1  uwe 
     51  1.1  uwe #include <dev/rasops/rasops.h>
     52  1.1  uwe #include <dev/wsfont/wsfont.h>
     53  1.1  uwe 
     54  1.1  uwe #include <dev/ic/igsfbreg.h>
     55  1.1  uwe #include <dev/ic/igsfbvar.h>
     56  1.1  uwe 
     57  1.1  uwe #include <uvm/uvm_extern.h>
     58  1.1  uwe 
     59  1.1  uwe 
     60  1.1  uwe /*
     61  1.1  uwe  * wsscreen
     62  1.1  uwe  */
     63  1.1  uwe 
     64  1.1  uwe /* filled from rasops_info in igsfb_common_init */
     65  1.1  uwe static struct wsscreen_descr igsfb_stdscreen = {
     66  1.1  uwe 	"std",			/* name */
     67  1.1  uwe 	0, 0,			/* ncols, nrows */
     68  1.1  uwe 	NULL,			/* textops */
     69  1.1  uwe 	0, 0,			/* fontwidth, fontheight */
     70  1.1  uwe 	0			/* capabilities */
     71  1.1  uwe };
     72  1.1  uwe 
     73  1.1  uwe static const struct wsscreen_descr *_igsfb_scrlist[] = {
     74  1.1  uwe 	&igsfb_stdscreen,
     75  1.1  uwe };
     76  1.1  uwe 
     77  1.1  uwe static const struct wsscreen_list igsfb_screenlist = {
     78  1.1  uwe 	sizeof(_igsfb_scrlist) / sizeof(struct wsscreen_descr *),
     79  1.1  uwe 	_igsfb_scrlist
     80  1.1  uwe };
     81  1.1  uwe 
     82  1.1  uwe 
     83  1.1  uwe /*
     84  1.1  uwe  * wsdisplay_accessops
     85  1.1  uwe  */
     86  1.1  uwe 
     87  1.1  uwe static int	igsfb_ioctl(void *, u_long, caddr_t, int, struct proc *);
     88  1.1  uwe static paddr_t	igsfb_mmap(void *, off_t, int);
     89  1.1  uwe 
     90  1.1  uwe static int	igsfb_alloc_screen(void *, const struct wsscreen_descr *,
     91  1.1  uwe 				   void **, int *, int *, long *);
     92  1.1  uwe static void	igsfb_free_screen(void *, void *);
     93  1.1  uwe static int	igsfb_show_screen(void *, void *, int,
     94  1.1  uwe 				  void (*) (void *, int, int), void *);
     95  1.1  uwe 
     96  1.1  uwe static const struct wsdisplay_accessops igsfb_accessops = {
     97  1.1  uwe 	igsfb_ioctl,
     98  1.1  uwe 	igsfb_mmap,
     99  1.1  uwe 	igsfb_alloc_screen,
    100  1.1  uwe 	igsfb_free_screen,
    101  1.1  uwe 	igsfb_show_screen,
    102  1.1  uwe 	NULL /* load_font */
    103  1.1  uwe };
    104  1.1  uwe 
    105  1.1  uwe 
    106  1.1  uwe /*
    107  1.1  uwe  * internal functions
    108  1.1  uwe  */
    109  1.1  uwe static void	igsfb_common_init(struct igsfb_softc *);
    110  1.1  uwe static void	igsfb_init_bit_tables(struct igsfb_softc *);
    111  1.1  uwe static void	igsfb_blank_screen(struct igsfb_softc *, int);
    112  1.1  uwe static int	igsfb_get_cmap(struct igsfb_softc *, struct wsdisplay_cmap *);
    113  1.1  uwe static int	igsfb_set_cmap(struct igsfb_softc *, struct wsdisplay_cmap *);
    114  1.1  uwe static void	igsfb_update_cmap(struct igsfb_softc *sc, u_int, u_int);
    115  1.1  uwe static void	igsfb_set_curpos(struct igsfb_softc *,
    116  1.1  uwe 				 struct wsdisplay_curpos *);
    117  1.1  uwe static void	igsfb_update_curpos(struct igsfb_softc *);
    118  1.1  uwe static int	igsfb_get_cursor(struct igsfb_softc *,
    119  1.1  uwe 				 struct wsdisplay_cursor *);
    120  1.1  uwe static int	igsfb_set_cursor(struct igsfb_softc *,
    121  1.1  uwe 				 struct wsdisplay_cursor *);
    122  1.1  uwe static void	igsfb_update_cursor(struct igsfb_softc *, u_int);
    123  1.1  uwe static void	igsfb_convert_cursor_data(struct igsfb_softc *, u_int, u_int);
    124  1.1  uwe 
    125  1.1  uwe /*
    126  1.1  uwe  * bit expanders
    127  1.1  uwe  */
    128  1.1  uwe static u_int16_t igsfb_spread_bits_8(u_int8_t);
    129  1.1  uwe 
    130  1.1  uwe struct igs_bittab *igsfb_bittab = NULL;
    131  1.1  uwe struct igs_bittab *igsfb_bittab_bswap = NULL;
    132  1.1  uwe 
    133  1.1  uwe static __inline__ u_int16_t
    134  1.1  uwe igsfb_spread_bits_8(b)
    135  1.1  uwe 	u_int8_t b;
    136  1.1  uwe {
    137  1.1  uwe 	u_int16_t s = b;
    138  1.1  uwe 
    139  1.1  uwe 	s = ((s & 0x00f0) << 4) | (s & 0x000f);
    140  1.1  uwe 	s = ((s & 0x0c0c) << 2) | (s & 0x0303);
    141  1.1  uwe 	s = ((s & 0x2222) << 1) | (s & 0x1111);
    142  1.1  uwe 	return (s);
    143  1.1  uwe }
    144  1.1  uwe 
    145  1.1  uwe 
    146  1.1  uwe /*
    147  1.1  uwe  * Enable Video.  This might go through either memory or i/o space and
    148  1.1  uwe  * requires access to registers that we don't need for normal
    149  1.1  uwe  * operation.  So for greater flexibility this function takes bus tag
    150  1.1  uwe  * and base address, not the igsfb_softc.
    151  1.1  uwe  */
    152  1.1  uwe int
    153  1.1  uwe igsfb_io_enable(bt, base)
    154  1.1  uwe 	bus_space_tag_t bt;
    155  1.1  uwe 	bus_addr_t base;
    156  1.1  uwe {
    157  1.1  uwe 	bus_space_handle_t vdoh;
    158  1.1  uwe 	bus_space_handle_t vseh;
    159  1.1  uwe 	int ret;
    160  1.1  uwe 
    161  1.1  uwe 	ret = bus_space_map(bt, base + IGS_VDO, 1, 0, &vdoh);
    162  1.1  uwe 	if (ret != 0) {
    163  1.1  uwe 		printf("unable to map VDO register\n");
    164  1.1  uwe 		return (ret);
    165  1.1  uwe 	}
    166  1.1  uwe 
    167  1.1  uwe 	ret = bus_space_map(bt, base + IGS_VSE, 1, 0, &vseh);
    168  1.1  uwe 	if (ret != 0) {
    169  1.1  uwe 		bus_space_unmap(bt, vdoh, 1);
    170  1.1  uwe 		printf("unable to map VSE register\n");
    171  1.1  uwe 		return (ret);
    172  1.1  uwe 	}
    173  1.1  uwe 
    174  1.1  uwe 	/* enable video: start decoding i/o space accesses */
    175  1.1  uwe 	bus_space_write_1(bt, vdoh, 0, IGS_VDO_ENABLE | IGS_VDO_SETUP);
    176  1.1  uwe 	bus_space_write_1(bt, vseh, 0, IGS_VSE_ENABLE);
    177  1.1  uwe 	bus_space_write_1(bt, vdoh, 0, IGS_VDO_ENABLE);
    178  1.1  uwe 
    179  1.1  uwe 	bus_space_unmap(bt, vdoh, 1);
    180  1.1  uwe 	bus_space_unmap(bt, vseh, 1);
    181  1.1  uwe 
    182  1.1  uwe 	return (0);
    183  1.1  uwe }
    184  1.1  uwe 
    185  1.1  uwe 
    186  1.1  uwe /*
    187  1.1  uwe  * Enable linear: start decoding memory space accesses.
    188  1.1  uwe  * while here, enable coprocessor and set its addrress to 0xbf000.
    189  1.1  uwe  */
    190  1.1  uwe void
    191  1.1  uwe igsfb_mem_enable(sc)
    192  1.1  uwe 	struct igsfb_softc *sc;
    193  1.1  uwe {
    194  1.1  uwe 
    195  1.1  uwe 	igs_ext_write(sc->sc_iot, sc->sc_ioh, IGS_EXT_BIU_MISC_CTL,
    196  1.1  uwe 		      IGS_EXT_BIU_LINEAREN
    197  1.1  uwe 		      | IGS_EXT_BIU_COPREN
    198  1.1  uwe 		      | IGS_EXT_BIU_COPASELB);
    199  1.1  uwe }
    200  1.1  uwe 
    201  1.1  uwe 
    202  1.1  uwe /*
    203  1.1  uwe  * Finish off the attach.  Bus specific attach method should have
    204  1.1  uwe  * enabled io and memory accesses and mapped io and cop registers.
    205  1.1  uwe  */
    206  1.1  uwe void
    207  1.1  uwe igsfb_common_attach(sc, isconsole)
    208  1.1  uwe 	struct igsfb_softc *sc;
    209  1.1  uwe 	int isconsole;
    210  1.1  uwe {
    211  1.1  uwe 	bus_addr_t craddr;
    212  1.1  uwe 	off_t croffset;
    213  1.1  uwe 	struct rasops_info *ri;
    214  1.1  uwe 	struct wsemuldisplaydev_attach_args waa;
    215  1.1  uwe 	u_int8_t busctl, curctl;
    216  1.1  uwe 
    217  1.1  uwe 	busctl = igs_ext_read(sc->sc_iot, sc->sc_ioh, IGS_EXT_BUS_CTL);
    218  1.1  uwe 	if (busctl & 0x2)
    219  1.1  uwe 		sc->sc_memsz = 4 * 1024 * 1024;
    220  1.1  uwe 	else if (busctl & 0x1)
    221  1.1  uwe 		sc->sc_memsz = 2 * 1024 * 1024;
    222  1.1  uwe 	else
    223  1.1  uwe 		sc->sc_memsz = 1 * 1024 * 1024;
    224  1.1  uwe 
    225  1.1  uwe 	/*
    226  1.1  uwe 	 * Don't map in all N megs, just the amount we need for wsscreen
    227  1.1  uwe 	 */
    228  1.1  uwe 	sc->sc_fbsz = 1024 * 768; /* XXX: 8bpp specific */
    229  1.1  uwe 	if (bus_space_map(sc->sc_memt, sc->sc_memaddr, sc->sc_fbsz,
    230  1.1  uwe 			  sc->sc_memflags | BUS_SPACE_MAP_LINEAR,
    231  1.1  uwe 			  &sc->sc_fbh) != 0)
    232  1.1  uwe 	{
    233  1.1  uwe 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, IGS_IO_SIZE);
    234  1.1  uwe 		printf("unable to map framebuffer\n");
    235  1.1  uwe 		return;
    236  1.1  uwe 	}
    237  1.1  uwe 
    238  1.1  uwe 	/*
    239  1.1  uwe 	 * 1Kb for cursor sprite data at the very end of linear space
    240  1.1  uwe 	 */
    241  1.1  uwe 	croffset = sc->sc_memsz - IGS_CURSOR_DATA_SIZE;
    242  1.1  uwe 	craddr = sc->sc_memaddr + croffset;
    243  1.1  uwe 	if (bus_space_map(sc->sc_memt, craddr, IGS_CURSOR_DATA_SIZE,
    244  1.1  uwe 			  sc->sc_memflags | BUS_SPACE_MAP_LINEAR,
    245  1.1  uwe 			  &sc->sc_crh) != 0)
    246  1.1  uwe 	{
    247  1.1  uwe 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, IGS_IO_SIZE);
    248  1.1  uwe 		bus_space_unmap(sc->sc_memt, sc->sc_fbh, sc->sc_fbsz);
    249  1.1  uwe 		printf("unable to map cursor sprite region\n");
    250  1.1  uwe 		return;
    251  1.1  uwe 	}
    252  1.1  uwe 
    253  1.1  uwe 	/*
    254  1.1  uwe 	 * Tell device where cursor sprite data are located in linear
    255  1.1  uwe 	 * space (it takes data offset in 1k units).
    256  1.1  uwe 	 */
    257  1.1  uwe 	croffset >>= 10;
    258  1.1  uwe 	igs_ext_write(sc->sc_iot, sc->sc_ioh,
    259  1.1  uwe 		      IGS_EXT_SPRITE_DATA_LO, croffset & 0xff);
    260  1.1  uwe 	igs_ext_write(sc->sc_iot, sc->sc_ioh,
    261  1.1  uwe 		      IGS_EXT_SPRITE_DATA_HI, (croffset >> 8) & 0xf);
    262  1.1  uwe 
    263  1.1  uwe 	memset(&sc->sc_cursor, 0, sizeof(struct igs_hwcursor));
    264  1.1  uwe 	memset(bus_space_vaddr(sc->sc_memt, sc->sc_crh),
    265  1.1  uwe 	       0xaa, IGS_CURSOR_DATA_SIZE); /* transparent */
    266  1.1  uwe 
    267  1.1  uwe 	curctl = igs_ext_read(sc->sc_iot, sc->sc_ioh, IGS_EXT_SPRITE_CTL);
    268  1.1  uwe 	curctl |= IGS_EXT_SPRITE_64x64;
    269  1.1  uwe 	curctl &= ~IGS_EXT_SPRITE_VISIBLE;
    270  1.1  uwe 	igs_ext_write(sc->sc_iot, sc->sc_ioh, IGS_EXT_SPRITE_CTL, curctl);
    271  1.1  uwe 
    272  1.1  uwe 	/* bit expanders for cursor sprite data */
    273  1.1  uwe 	igsfb_init_bit_tables(sc);
    274  1.1  uwe 
    275  1.1  uwe 	/* alloc and cross-link raster ops */
    276  1.1  uwe 	ri = malloc(sizeof(struct rasops_info), M_DEVBUF, M_NOWAIT | M_ZERO);
    277  1.1  uwe 	if (ri == NULL)
    278  1.1  uwe 		panic("unable to allocate rasops");
    279  1.1  uwe 	ri->ri_hw = sc;
    280  1.1  uwe 	sc->sc_ri = ri;
    281  1.1  uwe 
    282  1.1  uwe 	igsfb_common_init(sc);
    283  1.1  uwe 
    284  1.1  uwe 	/*
    285  1.1  uwe 	 * XXX: console attachment needs rethinking
    286  1.1  uwe 	 */
    287  1.1  uwe 	if (isconsole) {
    288  1.1  uwe 		long defattr;
    289  1.1  uwe 		(*ri->ri_ops.alloc_attr)(ri, 0, 0, 0, &defattr);
    290  1.1  uwe 		wsdisplay_cnattach(&igsfb_stdscreen, ri, 0, 0, defattr);
    291  1.1  uwe 	}
    292  1.1  uwe 
    293  1.1  uwe 
    294  1.1  uwe 	printf("%s: %dx%d, %dbpp\n",
    295  1.1  uwe 	       sc->sc_dev.dv_xname, ri->ri_width, ri->ri_height, ri->ri_depth);
    296  1.1  uwe 
    297  1.1  uwe 	/* attach wsdisplay */
    298  1.1  uwe 	waa.console = isconsole;
    299  1.1  uwe 	waa.scrdata = &igsfb_screenlist;
    300  1.1  uwe 	waa.accessops = &igsfb_accessops;
    301  1.1  uwe 	waa.accesscookie = sc;
    302  1.1  uwe 
    303  1.1  uwe 	config_found(&sc->sc_dev, &waa, wsemuldisplaydevprint);
    304  1.1  uwe }
    305  1.1  uwe 
    306  1.1  uwe 
    307  1.1  uwe /*
    308  1.1  uwe  * Cursor sprite data are in 2bpp.  Incoming image/mask are in 1bpp.
    309  1.1  uwe  * Prebuild tables to expand 1bpp->2bpp with bswapping if neccessary.
    310  1.1  uwe  */
    311  1.1  uwe static void
    312  1.1  uwe igsfb_init_bit_tables(sc)
    313  1.1  uwe 	struct igsfb_softc *sc;
    314  1.1  uwe {
    315  1.1  uwe 	struct igs_bittab *tab;
    316  1.1  uwe 	u_int i;
    317  1.1  uwe 
    318  1.1  uwe 	if (sc->sc_hwflags & IGSFB_HW_BSWAP) {
    319  1.1  uwe 		if (igsfb_bittab_bswap == NULL) {
    320  1.1  uwe 			tab = malloc(sizeof(struct igs_bittab),
    321  1.1  uwe 				     M_DEVBUF, M_NOWAIT);
    322  1.1  uwe 			for (i = 0; i < 256; ++i) {
    323  1.1  uwe 				u_int16_t s = igsfb_spread_bits_8(i);
    324  1.1  uwe 				tab->iexpand[i] = bswap16(s);
    325  1.1  uwe 				tab->mexpand[i] = bswap16((s << 1) | s);
    326  1.1  uwe 			}
    327  1.1  uwe 			igsfb_bittab_bswap = tab;
    328  1.1  uwe 		}
    329  1.1  uwe 		sc->sc_bittab = igsfb_bittab_bswap;
    330  1.1  uwe 	} else {
    331  1.1  uwe 		if (igsfb_bittab == NULL) {
    332  1.1  uwe 			tab = malloc(sizeof(struct igs_bittab),
    333  1.1  uwe 				     M_DEVBUF, M_NOWAIT);
    334  1.1  uwe 			for (i = 0; i < 256; ++i) {
    335  1.1  uwe 				u_int16_t s = igsfb_spread_bits_8(i);
    336  1.1  uwe 				tab->iexpand[i] = s;
    337  1.1  uwe 				tab->mexpand[i] = (s << 1) | s;
    338  1.1  uwe 			}
    339  1.1  uwe 			igsfb_bittab = tab;
    340  1.1  uwe 		}
    341  1.1  uwe 		sc->sc_bittab = igsfb_bittab;
    342  1.1  uwe 	}
    343  1.1  uwe }
    344  1.1  uwe 
    345  1.1  uwe /*
    346  1.1  uwe  * I/O and memory are mapped, video enabled, structures allocated.
    347  1.1  uwe  */
    348  1.1  uwe static void
    349  1.1  uwe igsfb_common_init(sc)
    350  1.1  uwe 	struct igsfb_softc *sc;
    351  1.1  uwe {
    352  1.1  uwe 	bus_space_tag_t iot = sc->sc_iot;
    353  1.1  uwe 	bus_space_handle_t ioh = sc->sc_ioh;
    354  1.1  uwe 	struct rasops_info *ri = sc->sc_ri;
    355  1.1  uwe 	int wsfcookie;
    356  1.1  uwe 	const u_int8_t *p;
    357  1.1  uwe 	int i;
    358  1.1  uwe 
    359  1.1  uwe 	sc->sc_blanked = 0;
    360  1.1  uwe 
    361  1.1  uwe 	ri->ri_flg = RI_CENTER | RI_CLEAR;
    362  1.1  uwe 	if (sc->sc_hwflags & IGSFB_HW_BSWAP)
    363  1.1  uwe 	    ri->ri_flg |= RI_BSWAP;
    364  1.1  uwe 
    365  1.1  uwe 	ri->ri_depth = 8;
    366  1.1  uwe 	ri->ri_width = 1024;
    367  1.1  uwe 	ri->ri_height = 768;
    368  1.1  uwe 	ri->ri_stride = 1024;
    369  1.1  uwe 	ri->ri_bits = (u_char *)sc->sc_fbh;
    370  1.1  uwe 
    371  1.1  uwe 	/*
    372  1.1  uwe 	 * Initialize wsfont related stuff.
    373  1.1  uwe 	 */
    374  1.1  uwe 	wsfont_init();
    375  1.1  uwe 
    376  1.1  uwe 	/* prefer gallant that is identical to the one the prom uses */
    377  1.1  uwe 	wsfcookie = wsfont_find("Gallant", 12, 22, 0,
    378  1.1  uwe 				WSDISPLAY_FONTORDER_L2R,
    379  1.1  uwe 				WSDISPLAY_FONTORDER_L2R);
    380  1.1  uwe 	if (wsfcookie <= 0) {
    381  1.1  uwe #ifdef DIAGNOSTIC
    382  1.1  uwe 		printf("%s: unable to find font Gallant 12x22\n",
    383  1.1  uwe 		       sc->sc_dev.dv_xname);
    384  1.1  uwe #endif
    385  1.1  uwe 		/* any font at all? */
    386  1.1  uwe 		wsfcookie = wsfont_find(NULL, 0, 0, 0,
    387  1.1  uwe 					WSDISPLAY_FONTORDER_L2R,
    388  1.1  uwe 					WSDISPLAY_FONTORDER_L2R);
    389  1.1  uwe 	}
    390  1.1  uwe 
    391  1.1  uwe 	if (wsfcookie <= 0) {
    392  1.1  uwe 		printf("%s: unable to find any fonts\n", sc->sc_dev.dv_xname);
    393  1.1  uwe 		return;
    394  1.1  uwe 	}
    395  1.1  uwe 
    396  1.1  uwe 	if (wsfont_lock(wsfcookie, &ri->ri_font) != 0) {
    397  1.1  uwe 		printf("%s: unable to lock font\n", sc->sc_dev.dv_xname);
    398  1.1  uwe 		return;
    399  1.1  uwe 	}
    400  1.1  uwe 	ri->ri_wsfcookie = wsfcookie;
    401  1.1  uwe 
    402  1.1  uwe 
    403  1.1  uwe 	/*
    404  1.1  uwe 	 * Initialize colormap related stuff.
    405  1.1  uwe 	 */
    406  1.1  uwe 
    407  1.1  uwe 	/* ANSI color map */
    408  1.1  uwe 	p = rasops_cmap;
    409  1.1  uwe 	for (i = 0; i < IGS_CMAP_SIZE; ++i, p += 3) { /* software copy */
    410  1.1  uwe 		sc->sc_cmap.r[i] = p[0];
    411  1.1  uwe 		sc->sc_cmap.g[i] = p[1];
    412  1.1  uwe 		sc->sc_cmap.b[i] = p[2];
    413  1.1  uwe 	}
    414  1.1  uwe 	igsfb_update_cmap(sc, 0, IGS_CMAP_SIZE);
    415  1.1  uwe 
    416  1.1  uwe 	/* set overscan color r/g/b (XXX: use defattr's rgb?) */
    417  1.1  uwe 	igs_ext_write(iot, ioh, IGS_EXT_OVERSCAN_RED,   0);
    418  1.1  uwe 	igs_ext_write(iot, ioh, IGS_EXT_OVERSCAN_GREEN, 0);
    419  1.1  uwe 	igs_ext_write(iot, ioh, IGS_EXT_OVERSCAN_BLUE,  0);
    420  1.1  uwe 
    421  1.1  uwe 
    422  1.1  uwe 	/* TODO: compute term size based on font dimensions? */
    423  1.1  uwe 	rasops_init(ri, 34, 80);
    424  1.1  uwe 
    425  1.1  uwe 	igsfb_stdscreen.nrows = ri->ri_rows;
    426  1.1  uwe 	igsfb_stdscreen.ncols = ri->ri_cols;
    427  1.1  uwe 	igsfb_stdscreen.textops = &ri->ri_ops;
    428  1.1  uwe 	igsfb_stdscreen.capabilities = ri->ri_caps;
    429  1.1  uwe }
    430  1.1  uwe 
    431  1.1  uwe 
    432  1.1  uwe /*
    433  1.1  uwe  * wsdisplay_accessops: mmap()
    434  1.1  uwe  */
    435  1.1  uwe static paddr_t
    436  1.1  uwe igsfb_mmap(v, offset, prot)
    437  1.1  uwe 	void *v;
    438  1.1  uwe 	off_t offset;
    439  1.1  uwe 	int prot;
    440  1.1  uwe {
    441  1.1  uwe 	struct igsfb_softc *sc = v;
    442  1.1  uwe 
    443  1.1  uwe 	if (offset >= sc->sc_memsz || offset < 0)
    444  1.1  uwe 		return (-1);
    445  1.1  uwe 
    446  1.1  uwe 	return (bus_space_mmap(sc->sc_memt, sc->sc_memaddr, offset, prot,
    447  1.1  uwe 			       sc->sc_memflags | BUS_SPACE_MAP_LINEAR));
    448  1.1  uwe }
    449  1.1  uwe 
    450  1.1  uwe 
    451  1.1  uwe /*
    452  1.1  uwe  * wsdisplay_accessops: ioctl()
    453  1.1  uwe  */
    454  1.1  uwe static int
    455  1.1  uwe igsfb_ioctl(v, cmd, data, flag, p)
    456  1.1  uwe 	void *v;
    457  1.1  uwe 	u_long cmd;
    458  1.1  uwe 	caddr_t data;
    459  1.1  uwe 	int flag;
    460  1.1  uwe 	struct proc *p;
    461  1.1  uwe {
    462  1.1  uwe 	struct igsfb_softc *sc = v;
    463  1.1  uwe 	struct rasops_info *ri = sc->sc_ri;
    464  1.1  uwe 	int turnoff;
    465  1.1  uwe 
    466  1.1  uwe 	switch (cmd) {
    467  1.1  uwe 
    468  1.1  uwe 	case WSDISPLAYIO_GTYPE:
    469  1.1  uwe 		*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
    470  1.1  uwe 		return (0);
    471  1.1  uwe 
    472  1.1  uwe 	case WSDISPLAYIO_GINFO:
    473  1.1  uwe #define	wsd_fbip ((struct wsdisplay_fbinfo *)data)
    474  1.1  uwe 		wsd_fbip->height = ri->ri_height;
    475  1.1  uwe 		wsd_fbip->width = ri->ri_width;
    476  1.1  uwe 		wsd_fbip->depth = ri->ri_depth;
    477  1.1  uwe 		wsd_fbip->cmsize = IGS_CMAP_SIZE;
    478  1.1  uwe #undef wsd_fbip
    479  1.1  uwe 		return (0);
    480  1.1  uwe 
    481  1.1  uwe 	case WSDISPLAYIO_GVIDEO:
    482  1.1  uwe 		*(u_int *)data = sc->sc_blanked ?
    483  1.1  uwe 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    484  1.1  uwe 		return (0);
    485  1.1  uwe 
    486  1.1  uwe 	case WSDISPLAYIO_SVIDEO:
    487  1.1  uwe 		turnoff = (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF);
    488  1.1  uwe 		if (sc->sc_blanked != turnoff) {
    489  1.1  uwe 			sc->sc_blanked = turnoff;
    490  1.1  uwe 			igsfb_blank_screen(sc, sc->sc_blanked);
    491  1.1  uwe 		}
    492  1.1  uwe 		return (0);
    493  1.1  uwe 
    494  1.1  uwe 	case WSDISPLAYIO_GETCMAP:
    495  1.1  uwe 		return (igsfb_get_cmap(sc, (struct wsdisplay_cmap *)data));
    496  1.1  uwe 
    497  1.1  uwe 	case WSDISPLAYIO_PUTCMAP:
    498  1.1  uwe 		return (igsfb_set_cmap(sc, (struct wsdisplay_cmap *)data));
    499  1.1  uwe 
    500  1.1  uwe 	case WSDISPLAYIO_GCURMAX:
    501  1.1  uwe 		((struct wsdisplay_curpos *)data)->x = IGS_CURSOR_MAX_SIZE;
    502  1.1  uwe 		((struct wsdisplay_curpos *)data)->y = IGS_CURSOR_MAX_SIZE;
    503  1.1  uwe 		return (0);
    504  1.1  uwe 
    505  1.1  uwe 	case WSDISPLAYIO_GCURPOS:
    506  1.1  uwe 		*(struct wsdisplay_curpos *)data = sc->sc_cursor.cc_pos;
    507  1.1  uwe 		return (0);
    508  1.1  uwe 
    509  1.1  uwe 	case WSDISPLAYIO_SCURPOS:
    510  1.1  uwe 		igsfb_set_curpos(sc, (struct wsdisplay_curpos *)data);
    511  1.1  uwe 		return (0);
    512  1.1  uwe 
    513  1.1  uwe 	case WSDISPLAYIO_GCURSOR:
    514  1.1  uwe 		return (igsfb_get_cursor(sc, (struct wsdisplay_cursor *)data));
    515  1.1  uwe 
    516  1.1  uwe 	case WSDISPLAYIO_SCURSOR:
    517  1.1  uwe 		return (igsfb_set_cursor(sc, (struct wsdisplay_cursor *)data));
    518  1.1  uwe 	}
    519  1.1  uwe 
    520  1.1  uwe 	return (EPASSTHROUGH);
    521  1.1  uwe }
    522  1.1  uwe 
    523  1.1  uwe 
    524  1.1  uwe /*
    525  1.1  uwe  * wsdisplay_accessops: ioctl(WSDISPLAYIO_SVIDEO)
    526  1.1  uwe  */
    527  1.1  uwe static void
    528  1.1  uwe igsfb_blank_screen(sc, blank)
    529  1.1  uwe 	struct igsfb_softc *sc;
    530  1.1  uwe 	int blank;
    531  1.1  uwe {
    532  1.1  uwe 
    533  1.1  uwe 	igs_ext_write(sc->sc_iot, sc->sc_ioh,
    534  1.1  uwe 		      IGS_EXT_SYNC_CTL,
    535  1.1  uwe 		      blank ? IGS_EXT_SYNC_H0 | IGS_EXT_SYNC_V0
    536  1.1  uwe 			    : 0);
    537  1.1  uwe }
    538  1.1  uwe 
    539  1.1  uwe 
    540  1.1  uwe /*
    541  1.1  uwe  * wsdisplay_accessops: ioctl(WSDISPLAYIO_GETCMAP)
    542  1.1  uwe  *   Served from software cmap copy.
    543  1.1  uwe  */
    544  1.1  uwe static int
    545  1.1  uwe igsfb_get_cmap(sc, p)
    546  1.1  uwe 	struct igsfb_softc *sc;
    547  1.1  uwe 	struct wsdisplay_cmap *p;
    548  1.1  uwe {
    549  1.1  uwe 	u_int index = p->index, count = p->count;
    550  1.1  uwe 
    551  1.1  uwe 	if (index >= IGS_CMAP_SIZE || (index + count) > IGS_CMAP_SIZE)
    552  1.1  uwe 		return (EINVAL);
    553  1.1  uwe 
    554  1.1  uwe 	if (!uvm_useracc(p->red, count, B_WRITE) ||
    555  1.1  uwe 	    !uvm_useracc(p->green, count, B_WRITE) ||
    556  1.1  uwe 	    !uvm_useracc(p->blue, count, B_WRITE))
    557  1.1  uwe 		return (EFAULT);
    558  1.1  uwe 
    559  1.1  uwe 	copyout(&sc->sc_cmap.r[index], p->red, count);
    560  1.1  uwe 	copyout(&sc->sc_cmap.g[index], p->green, count);
    561  1.1  uwe 	copyout(&sc->sc_cmap.b[index], p->blue, count);
    562  1.1  uwe 
    563  1.1  uwe 	return (0);
    564  1.1  uwe }
    565  1.1  uwe 
    566  1.1  uwe 
    567  1.1  uwe /*
    568  1.1  uwe  * wsdisplay_accessops: ioctl(WSDISPLAYIO_SETCMAP)
    569  1.1  uwe  *   Set software cmap copy and propagate changed range to device.
    570  1.1  uwe  */
    571  1.1  uwe static int
    572  1.1  uwe igsfb_set_cmap(sc, p)
    573  1.1  uwe 	struct igsfb_softc *sc;
    574  1.1  uwe 	struct wsdisplay_cmap *p;
    575  1.1  uwe {
    576  1.1  uwe 	u_int index = p->index, count = p->count;
    577  1.1  uwe 
    578  1.1  uwe 	if (index >= IGS_CMAP_SIZE || (index + count) > IGS_CMAP_SIZE)
    579  1.1  uwe 		return (EINVAL);
    580  1.1  uwe 
    581  1.1  uwe 	if (!uvm_useracc(p->red, count, B_READ) ||
    582  1.1  uwe 	    !uvm_useracc(p->green, count, B_READ) ||
    583  1.1  uwe 	    !uvm_useracc(p->blue, count, B_READ))
    584  1.1  uwe 		return (EFAULT);
    585  1.1  uwe 
    586  1.1  uwe 	copyin(p->red, &sc->sc_cmap.r[index], count);
    587  1.1  uwe 	copyin(p->green, &sc->sc_cmap.g[index], count);
    588  1.1  uwe 	copyin(p->blue, &sc->sc_cmap.b[index], count);
    589  1.1  uwe 
    590  1.1  uwe 	igsfb_update_cmap(sc, p->index, p->count);
    591  1.1  uwe 
    592  1.1  uwe 	return (0);
    593  1.1  uwe }
    594  1.1  uwe 
    595  1.1  uwe 
    596  1.1  uwe /*
    597  1.1  uwe  * Propagate specified part of the software cmap copy to device.
    598  1.1  uwe  */
    599  1.1  uwe static void
    600  1.1  uwe igsfb_update_cmap(sc, index, count)
    601  1.1  uwe 	struct igsfb_softc *sc;
    602  1.1  uwe 	u_int index, count;
    603  1.1  uwe {
    604  1.1  uwe 	bus_space_tag_t t;
    605  1.1  uwe 	bus_space_handle_t h;
    606  1.1  uwe 	u_int last, i;
    607  1.1  uwe 
    608  1.1  uwe 	if (index >= IGS_CMAP_SIZE)
    609  1.1  uwe 		return;
    610  1.1  uwe 
    611  1.1  uwe 	last = index + count;
    612  1.1  uwe 	if (last > IGS_CMAP_SIZE)
    613  1.1  uwe 		last = IGS_CMAP_SIZE;
    614  1.1  uwe 
    615  1.1  uwe 	t = sc->sc_iot;
    616  1.1  uwe 	h = sc->sc_ioh;
    617  1.1  uwe 
    618  1.1  uwe 	/* start palette writing, index is autoincremented by hardware */
    619  1.1  uwe 	bus_space_write_1(t, h, IGS_DAC_PEL_WRITE_IDX, index);
    620  1.1  uwe 
    621  1.1  uwe 	for (i = index; i < last; ++i) {
    622  1.1  uwe 		bus_space_write_1(t, h, IGS_DAC_PEL_DATA, sc->sc_cmap.r[i]);
    623  1.1  uwe 		bus_space_write_1(t, h, IGS_DAC_PEL_DATA, sc->sc_cmap.g[i]);
    624  1.1  uwe 		bus_space_write_1(t, h, IGS_DAC_PEL_DATA, sc->sc_cmap.b[i]);
    625  1.1  uwe 	}
    626  1.1  uwe }
    627  1.1  uwe 
    628  1.1  uwe 
    629  1.1  uwe /*
    630  1.1  uwe  * wsdisplay_accessops: ioctl(WSDISPLAYIO_SCURPOS)
    631  1.1  uwe  */
    632  1.1  uwe static void
    633  1.1  uwe igsfb_set_curpos(sc, curpos)
    634  1.1  uwe 	struct igsfb_softc *sc;
    635  1.1  uwe 	struct wsdisplay_curpos *curpos;
    636  1.1  uwe {
    637  1.1  uwe 	struct rasops_info *ri = sc->sc_ri;
    638  1.1  uwe 	int x = curpos->x, y = curpos->y;
    639  1.1  uwe 
    640  1.1  uwe 	if (y < 0)
    641  1.1  uwe 		y = 0;
    642  1.1  uwe 	else if (y > ri->ri_height)
    643  1.1  uwe 		y = ri->ri_height;
    644  1.1  uwe 	if (x < 0)
    645  1.1  uwe 		x = 0;
    646  1.1  uwe 	else if (x > ri->ri_width)
    647  1.1  uwe 		x = ri->ri_width;
    648  1.1  uwe 	sc->sc_cursor.cc_pos.x = x;
    649  1.1  uwe 	sc->sc_cursor.cc_pos.y = y;
    650  1.1  uwe 
    651  1.1  uwe 	igsfb_update_curpos(sc);
    652  1.1  uwe }
    653  1.1  uwe 
    654  1.1  uwe 
    655  1.1  uwe static void
    656  1.1  uwe igsfb_update_curpos(sc)
    657  1.1  uwe 	struct igsfb_softc *sc;
    658  1.1  uwe {
    659  1.1  uwe 	bus_space_tag_t t;
    660  1.1  uwe 	bus_space_handle_t h;
    661  1.1  uwe 	int x, xoff, y, yoff;
    662  1.1  uwe 
    663  1.1  uwe 	xoff = 0;
    664  1.1  uwe 	x = sc->sc_cursor.cc_pos.x - sc->sc_cursor.cc_hot.x;
    665  1.1  uwe 	if (x < 0) {
    666  1.1  uwe 		x = 0;
    667  1.1  uwe 		xoff = -x;
    668  1.1  uwe 	}
    669  1.1  uwe 
    670  1.1  uwe 	yoff = 0;
    671  1.1  uwe 	y = sc->sc_cursor.cc_pos.y - sc->sc_cursor.cc_hot.y;
    672  1.1  uwe 	if (y < 0) {
    673  1.1  uwe 		y = 0;
    674  1.1  uwe 		yoff = -y;
    675  1.1  uwe 	}
    676  1.1  uwe 
    677  1.1  uwe 	t = sc->sc_iot;
    678  1.1  uwe 	h = sc->sc_ioh;
    679  1.1  uwe 
    680  1.1  uwe 	igs_ext_write(t, h, IGS_EXT_SPRITE_HSTART_LO, x & 0xff);
    681  1.1  uwe 	igs_ext_write(t, h, IGS_EXT_SPRITE_HSTART_HI, (x >> 8) & 0x07);
    682  1.1  uwe 	igs_ext_write(t, h, IGS_EXT_SPRITE_HPRESET, xoff & 0x3f);
    683  1.1  uwe 
    684  1.1  uwe 	igs_ext_write(t, h, IGS_EXT_SPRITE_VSTART_LO, y & 0xff);
    685  1.1  uwe 	igs_ext_write(t, h, IGS_EXT_SPRITE_VSTART_HI, (y >> 8) & 0x07);
    686  1.1  uwe 	igs_ext_write(t, h, IGS_EXT_SPRITE_VPRESET, yoff & 0x3f);
    687  1.1  uwe }
    688  1.1  uwe 
    689  1.1  uwe 
    690  1.1  uwe /*
    691  1.1  uwe  * wsdisplay_accessops: ioctl(WSDISPLAYIO_GCURSOR)
    692  1.1  uwe  */
    693  1.1  uwe static int
    694  1.1  uwe igsfb_get_cursor(sc, p)
    695  1.1  uwe 	struct igsfb_softc *sc;
    696  1.1  uwe 	struct wsdisplay_cursor *p;
    697  1.1  uwe {
    698  1.1  uwe 
    699  1.1  uwe 	/* XXX: TODO */
    700  1.1  uwe 	return (0);
    701  1.1  uwe }
    702  1.1  uwe 
    703  1.1  uwe 
    704  1.1  uwe /*
    705  1.1  uwe  * wsdisplay_accessops: ioctl(WSDISPLAYIO_SCURSOR)
    706  1.1  uwe  */
    707  1.1  uwe static int
    708  1.1  uwe igsfb_set_cursor(sc, p)
    709  1.1  uwe 	struct igsfb_softc *sc;
    710  1.1  uwe 	struct wsdisplay_cursor *p;
    711  1.1  uwe {
    712  1.1  uwe 	struct igs_hwcursor *cc;
    713  1.1  uwe 	u_int v, index, count, icount, iwidth;
    714  1.1  uwe 
    715  1.1  uwe 	cc = &sc->sc_cursor;
    716  1.1  uwe 	v = p->which;
    717  1.1  uwe 
    718  1.1  uwe 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    719  1.1  uwe 		index = p->cmap.index;
    720  1.1  uwe 		count = p->cmap.count;
    721  1.1  uwe 		if (index >= 2 || (index + count) > 2)
    722  1.1  uwe 			return (EINVAL);
    723  1.1  uwe 		if (!uvm_useracc(p->cmap.red, count, B_READ)
    724  1.1  uwe 		    || !uvm_useracc(p->cmap.green, count, B_READ)
    725  1.1  uwe 		    || !uvm_useracc(p->cmap.blue, count, B_READ))
    726  1.1  uwe 			return (EFAULT);
    727  1.1  uwe 	}
    728  1.1  uwe 
    729  1.1  uwe 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    730  1.1  uwe 		if (p->size.x > IGS_CURSOR_MAX_SIZE
    731  1.1  uwe 		    || p->size.y > IGS_CURSOR_MAX_SIZE)
    732  1.1  uwe 			return (EINVAL);
    733  1.1  uwe 
    734  1.1  uwe 		iwidth = (p->size.x + 7) >> 3; /* bytes per scan line */
    735  1.1  uwe 		icount = iwidth * p->size.y;
    736  1.1  uwe 		if (!uvm_useracc(p->image, icount, B_READ)
    737  1.1  uwe 		    || !uvm_useracc(p->mask, icount, B_READ))
    738  1.1  uwe 			return (EFAULT);
    739  1.1  uwe 	}
    740  1.1  uwe 
    741  1.1  uwe 	/* XXX: verify that hot is within size, pos within screen? */
    742  1.1  uwe 
    743  1.1  uwe 	/* arguments verified, do the processing */
    744  1.1  uwe 
    745  1.1  uwe 	if (v & WSDISPLAY_CURSOR_DOCUR)
    746  1.1  uwe 		sc->sc_curenb = p->enable;
    747  1.1  uwe 
    748  1.1  uwe 	if (v & WSDISPLAY_CURSOR_DOPOS)
    749  1.1  uwe 		cc->cc_pos = p->pos;
    750  1.1  uwe 
    751  1.1  uwe 	if (v & WSDISPLAY_CURSOR_DOHOT)
    752  1.1  uwe 		cc->cc_hot = p->hot;
    753  1.1  uwe 
    754  1.1  uwe 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    755  1.1  uwe 		copyin(p->cmap.red, &cc->cc_color[index], count);
    756  1.1  uwe 		copyin(p->cmap.green, &cc->cc_color[index + 2], count);
    757  1.1  uwe 		copyin(p->cmap.blue, &cc->cc_color[index + 4], count);
    758  1.1  uwe 	}
    759  1.1  uwe 
    760  1.1  uwe 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    761  1.1  uwe 		u_int trailing_bits;
    762  1.1  uwe 
    763  1.1  uwe 		copyin(p->image, cc->cc_image, icount);
    764  1.1  uwe 		copyin(p->mask, cc->cc_mask, icount);
    765  1.1  uwe 		cc->cc_size = p->size;
    766  1.1  uwe 
    767  1.1  uwe 		/* clear trailing bits in the "partial" mask bytes */
    768  1.1  uwe 		trailing_bits = p->size.x & 0x07;
    769  1.1  uwe 		if (trailing_bits != 0) {
    770  1.1  uwe 			const u_int cutmask = ~((~0) << trailing_bits);
    771  1.1  uwe 			u_char *mp;
    772  1.1  uwe 			u_int i;
    773  1.1  uwe 
    774  1.1  uwe 			mp = cc->cc_mask + iwidth - 1;
    775  1.1  uwe 			for (i = 0; i < p->size.y; ++i) {
    776  1.1  uwe 				*mp &= cutmask;
    777  1.1  uwe 				mp += iwidth;
    778  1.1  uwe 			}
    779  1.1  uwe 		}
    780  1.1  uwe 		igsfb_convert_cursor_data(sc, iwidth, p->size.y);
    781  1.1  uwe 	}
    782  1.1  uwe 
    783  1.1  uwe 	igsfb_update_cursor(sc, v);
    784  1.1  uwe 	return (0);
    785  1.1  uwe }
    786  1.1  uwe 
    787  1.1  uwe /*
    788  1.1  uwe  * Convert incoming 1bpp cursor image/mask into native 2bpp format.
    789  1.1  uwe  */
    790  1.1  uwe static void
    791  1.1  uwe igsfb_convert_cursor_data(sc, w, h)
    792  1.1  uwe 	struct igsfb_softc *sc;
    793  1.1  uwe 	u_int w, h;
    794  1.1  uwe {
    795  1.1  uwe 	struct igs_hwcursor *cc = &sc->sc_cursor;
    796  1.1  uwe 	struct igs_bittab *btab = sc->sc_bittab;
    797  1.1  uwe 	u_int8_t *ip, *mp;
    798  1.1  uwe 	u_int16_t *dp;
    799  1.1  uwe 	u_int line, i;
    800  1.1  uwe 
    801  1.1  uwe 	/* init sprite to be all transparent */
    802  1.1  uwe 	memset(cc->cc_sprite, 0xaa, IGS_CURSOR_DATA_SIZE);
    803  1.1  uwe 
    804  1.1  uwe 	/* first scanline */
    805  1.1  uwe 	ip = cc->cc_image;
    806  1.1  uwe 	mp = cc->cc_mask;
    807  1.1  uwe 	dp = cc->cc_sprite;
    808  1.1  uwe 
    809  1.1  uwe 	for (line = 0; line < h; ++line) {
    810  1.1  uwe 		for (i = 0; i < w; ++i) {
    811  1.1  uwe 			u_int16_t is = btab->iexpand[ip[i]];
    812  1.1  uwe 			u_int16_t ms = btab->mexpand[mp[i]];
    813  1.1  uwe 
    814  1.1  uwe 			/* NB: tables are pre-bswapped if needed */
    815  1.1  uwe 			dp[i] = (0xaaaa & ~ms) | (is & ms);
    816  1.1  uwe 		}
    817  1.1  uwe 
    818  1.1  uwe 		/* next scanline */
    819  1.1  uwe 		ip += w;
    820  1.1  uwe 		mp += w;
    821  1.1  uwe 		dp += 8;	/* 2bpp, 8 pixels per short = 8 shorts */
    822  1.1  uwe 	}
    823  1.1  uwe }
    824  1.1  uwe 
    825  1.1  uwe 
    826  1.1  uwe /*
    827  1.1  uwe  * Propagate cursor changes to device.
    828  1.1  uwe  * "which" is composed from WSDISPLAY_CURSOR_DO* bits.
    829  1.1  uwe  */
    830  1.1  uwe static void
    831  1.1  uwe igsfb_update_cursor(sc, which)
    832  1.1  uwe 	struct igsfb_softc *sc;
    833  1.1  uwe 	u_int which;
    834  1.1  uwe {
    835  1.1  uwe 	bus_space_tag_t iot = sc->sc_iot;
    836  1.1  uwe 	bus_space_handle_t ioh = sc->sc_ioh;
    837  1.1  uwe 	u_int8_t curctl;
    838  1.1  uwe 
    839  1.1  uwe 	/*
    840  1.1  uwe 	 * We will need to tweak sprite control register for cursor
    841  1.1  uwe 	 * visibility and cursor color map manipualtion.
    842  1.1  uwe 	 */
    843  1.1  uwe 	if (which & (WSDISPLAY_CURSOR_DOCUR | WSDISPLAY_CURSOR_DOCMAP)) {
    844  1.1  uwe 		curctl = igs_ext_read(iot, ioh, IGS_EXT_SPRITE_CTL);
    845  1.1  uwe 	}
    846  1.1  uwe 
    847  1.1  uwe 	if (which & WSDISPLAY_CURSOR_DOSHAPE) {
    848  1.1  uwe 		u_int8_t *dst = bus_space_vaddr(sc->sc_memt, sc->sc_crh);
    849  1.1  uwe 
    850  1.1  uwe 		/*
    851  1.1  uwe 		 * memcpy between spaces of different endianness would
    852  1.1  uwe 		 * be ... special.  We cannot be sure if memset gonna
    853  1.1  uwe 		 * push data in 4-byte chunks, we can't pre-bswap it,
    854  1.1  uwe 		 * so do it byte-by-byte to preserve byte ordering.
    855  1.1  uwe 		 */
    856  1.1  uwe 		if (sc->sc_hwflags & IGSFB_HW_BSWAP) {
    857  1.1  uwe 			u_int8_t *src = (u_int8_t *)sc->sc_cursor.cc_sprite;
    858  1.1  uwe 			int i;
    859  1.1  uwe 
    860  1.1  uwe 			for (i = 0; i < 1024; ++i)
    861  1.1  uwe 				*dst++ = *src++;
    862  1.1  uwe 		} else {
    863  1.1  uwe 			memcpy(dst, sc->sc_cursor.cc_sprite, 1024);
    864  1.1  uwe 		}
    865  1.1  uwe 	}
    866  1.1  uwe 
    867  1.1  uwe 	if (which & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
    868  1.1  uwe 		/* code shared with WSDISPLAYIO_SCURPOS */
    869  1.1  uwe 		igsfb_update_curpos(sc);
    870  1.1  uwe 	}
    871  1.1  uwe 
    872  1.1  uwe 	if (which & WSDISPLAY_CURSOR_DOCMAP) {
    873  1.1  uwe 		u_int8_t *p;
    874  1.1  uwe 
    875  1.1  uwe 		/* tell DAC we want access to the cursor palette */
    876  1.1  uwe 		igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
    877  1.1  uwe 			      curctl | IGS_EXT_SPRITE_SELECT);
    878  1.1  uwe 
    879  1.1  uwe 		p = sc->sc_cursor.cc_color;
    880  1.1  uwe 
    881  1.1  uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_WRITE_IDX, 0);
    882  1.1  uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[0]);
    883  1.1  uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[2]);
    884  1.1  uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[4]);
    885  1.1  uwe 
    886  1.1  uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_WRITE_IDX, 1);
    887  1.1  uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[1]);
    888  1.1  uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[3]);
    889  1.1  uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[5]);
    890  1.1  uwe 
    891  1.1  uwe 		/* restore access to normal palette */
    892  1.1  uwe 		igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL, curctl);
    893  1.1  uwe 	}
    894  1.1  uwe 
    895  1.1  uwe 	if (which & WSDISPLAY_CURSOR_DOCUR) {
    896  1.1  uwe 		if ((curctl & IGS_EXT_SPRITE_VISIBLE) == 0
    897  1.1  uwe 		    && sc->sc_curenb)
    898  1.1  uwe 			igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
    899  1.1  uwe 				      curctl | IGS_EXT_SPRITE_VISIBLE);
    900  1.1  uwe 		else if ((curctl & IGS_EXT_SPRITE_VISIBLE) != 0
    901  1.1  uwe 			 && !sc->sc_curenb)
    902  1.1  uwe 			igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
    903  1.1  uwe 				      curctl & ~IGS_EXT_SPRITE_VISIBLE);
    904  1.1  uwe 	}
    905  1.1  uwe }
    906  1.1  uwe 
    907  1.1  uwe 
    908  1.1  uwe /*
    909  1.1  uwe  * wsdisplay_accessops: alloc_screen()
    910  1.1  uwe  */
    911  1.1  uwe static int
    912  1.1  uwe igsfb_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
    913  1.1  uwe 	void *v;
    914  1.1  uwe 	const struct wsscreen_descr *type;
    915  1.1  uwe 	void **cookiep;
    916  1.1  uwe 	int *curxp, *curyp;
    917  1.1  uwe 	long *attrp;
    918  1.1  uwe {
    919  1.1  uwe 
    920  1.1  uwe 	/* TODO */
    921  1.1  uwe 	return (ENOMEM);
    922  1.1  uwe }
    923  1.1  uwe 
    924  1.1  uwe 
    925  1.1  uwe /*
    926  1.1  uwe  * wsdisplay_accessops: free_screen()
    927  1.1  uwe  */
    928  1.1  uwe static void
    929  1.1  uwe igsfb_free_screen(v, cookie)
    930  1.1  uwe 	void *v;
    931  1.1  uwe 	void *cookie;
    932  1.1  uwe {
    933  1.1  uwe 
    934  1.1  uwe 	/* TODO */
    935  1.1  uwe 	return;
    936  1.1  uwe }
    937  1.1  uwe 
    938  1.1  uwe 
    939  1.1  uwe /*
    940  1.1  uwe  * wsdisplay_accessops: show_screen()
    941  1.1  uwe  */
    942  1.1  uwe static int
    943  1.1  uwe igsfb_show_screen(v, cookie, waitok, cb, cbarg)
    944  1.1  uwe 	void *v;
    945  1.1  uwe 	void *cookie;
    946  1.1  uwe 	int waitok;
    947  1.1  uwe 	void (*cb)(void *, int, int);
    948  1.1  uwe 	void *cbarg;
    949  1.1  uwe {
    950  1.1  uwe 
    951  1.1  uwe 	return (0);
    952  1.1  uwe }
    953