Home | History | Annotate | Line # | Download | only in ic
igsfb.c revision 1.8
      1  1.8     uwe /*	$NetBSD: igsfb.c,v 1.8 2003/05/10 01:51:56 uwe Exp $ */
      2  1.1     uwe 
      3  1.1     uwe /*
      4  1.8     uwe  * Copyright (c) 2002, 2003 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.4     uwe  * Integraphics Systems IGA 168x and CyberPro series.
     32  1.1     uwe  */
     33  1.1     uwe #include <sys/cdefs.h>
     34  1.8     uwe __KERNEL_RCSID(0, "$NetBSD: igsfb.c,v 1.8 2003/05/10 01:51:56 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.2     uwe #include <sys/ioctl.h>
     42  1.1     uwe #include <sys/buf.h>
     43  1.2     uwe #include <uvm/uvm_extern.h>
     44  1.1     uwe 
     45  1.1     uwe #include <machine/bus.h>
     46  1.1     uwe 
     47  1.1     uwe #include <dev/wscons/wsdisplayvar.h>
     48  1.8     uwe #include <dev/wscons/wsconsio.h>
     49  1.8     uwe #include <dev/wsfont/wsfont.h>
     50  1.1     uwe #include <dev/rasops/rasops.h>
     51  1.1     uwe 
     52  1.1     uwe #include <dev/ic/igsfbreg.h>
     53  1.1     uwe #include <dev/ic/igsfbvar.h>
     54  1.1     uwe 
     55  1.1     uwe 
     56  1.8     uwe struct igsfb_devconfig igsfb_console_dc;
     57  1.8     uwe 
     58  1.1     uwe /*
     59  1.1     uwe  * wsscreen
     60  1.1     uwe  */
     61  1.1     uwe 
     62  1.1     uwe /* filled from rasops_info in igsfb_common_init */
     63  1.1     uwe static struct wsscreen_descr igsfb_stdscreen = {
     64  1.1     uwe 	"std",			/* name */
     65  1.1     uwe 	0, 0,			/* ncols, nrows */
     66  1.1     uwe 	NULL,			/* textops */
     67  1.1     uwe 	0, 0,			/* fontwidth, fontheight */
     68  1.1     uwe 	0			/* capabilities */
     69  1.1     uwe };
     70  1.1     uwe 
     71  1.1     uwe static const struct wsscreen_descr *_igsfb_scrlist[] = {
     72  1.1     uwe 	&igsfb_stdscreen,
     73  1.1     uwe };
     74  1.1     uwe 
     75  1.1     uwe static const struct wsscreen_list igsfb_screenlist = {
     76  1.1     uwe 	sizeof(_igsfb_scrlist) / sizeof(struct wsscreen_descr *),
     77  1.1     uwe 	_igsfb_scrlist
     78  1.1     uwe };
     79  1.1     uwe 
     80  1.1     uwe 
     81  1.1     uwe /*
     82  1.1     uwe  * wsdisplay_accessops
     83  1.1     uwe  */
     84  1.1     uwe 
     85  1.1     uwe static int	igsfb_ioctl(void *, u_long, caddr_t, int, struct proc *);
     86  1.1     uwe static paddr_t	igsfb_mmap(void *, off_t, int);
     87  1.1     uwe 
     88  1.1     uwe static int	igsfb_alloc_screen(void *, const struct wsscreen_descr *,
     89  1.1     uwe 				   void **, int *, int *, long *);
     90  1.1     uwe static void	igsfb_free_screen(void *, void *);
     91  1.1     uwe static int	igsfb_show_screen(void *, void *, int,
     92  1.1     uwe 				  void (*) (void *, int, int), void *);
     93  1.1     uwe 
     94  1.1     uwe static const struct wsdisplay_accessops igsfb_accessops = {
     95  1.1     uwe 	igsfb_ioctl,
     96  1.1     uwe 	igsfb_mmap,
     97  1.1     uwe 	igsfb_alloc_screen,
     98  1.1     uwe 	igsfb_free_screen,
     99  1.1     uwe 	igsfb_show_screen,
    100  1.1     uwe 	NULL /* load_font */
    101  1.1     uwe };
    102  1.1     uwe 
    103  1.1     uwe 
    104  1.1     uwe /*
    105  1.1     uwe  * internal functions
    106  1.1     uwe  */
    107  1.8     uwe static int	igsfb_init_video(struct igsfb_devconfig *);
    108  1.8     uwe static void	igsfb_init_cmap(struct igsfb_devconfig *);
    109  1.8     uwe static u_int16_t igsfb_spread_bits_8(u_int8_t);
    110  1.8     uwe static void	igsfb_init_bit_tables(struct igsfb_devconfig *);
    111  1.8     uwe static void	igsfb_init_wsdisplay(struct igsfb_devconfig *);
    112  1.8     uwe 
    113  1.8     uwe static void	igsfb_blank_screen(struct igsfb_devconfig *, int);
    114  1.8     uwe static int	igsfb_get_cmap(struct igsfb_devconfig *,
    115  1.8     uwe 			       struct wsdisplay_cmap *);
    116  1.8     uwe static int	igsfb_set_cmap(struct igsfb_devconfig *,
    117  1.8     uwe 			       struct wsdisplay_cmap *);
    118  1.8     uwe static void	igsfb_update_cmap(struct igsfb_devconfig *, u_int, u_int);
    119  1.8     uwe static void	igsfb_set_curpos(struct igsfb_devconfig *,
    120  1.1     uwe 				 struct wsdisplay_curpos *);
    121  1.8     uwe static void	igsfb_update_curpos(struct igsfb_devconfig *);
    122  1.8     uwe static int	igsfb_get_cursor(struct igsfb_devconfig *,
    123  1.1     uwe 				 struct wsdisplay_cursor *);
    124  1.8     uwe static int	igsfb_set_cursor(struct igsfb_devconfig *,
    125  1.1     uwe 				 struct wsdisplay_cursor *);
    126  1.8     uwe static void	igsfb_update_cursor(struct igsfb_devconfig *, u_int);
    127  1.8     uwe static void	igsfb_convert_cursor_data(struct igsfb_devconfig *,
    128  1.8     uwe 					  u_int, u_int);
    129  1.8     uwe 
    130  1.8     uwe 
    131  1.8     uwe int
    132  1.8     uwe igsfb_cnattach_subr(dc)
    133  1.8     uwe 	struct igsfb_devconfig *dc;
    134  1.8     uwe {
    135  1.8     uwe 	struct rasops_info *ri;
    136  1.8     uwe 	long defattr;
    137  1.1     uwe 
    138  1.8     uwe 	KASSERT(dc == &igsfb_console_dc);
    139  1.8     uwe 
    140  1.8     uwe 	igsfb_init_video(dc);
    141  1.8     uwe 	igsfb_init_wsdisplay(dc);
    142  1.1     uwe 
    143  1.8     uwe 	ri = &dc->dc_ri;
    144  1.8     uwe 	(*ri->ri_ops.allocattr)(ri,
    145  1.8     uwe 				WSCOL_BLACK, /* fg */
    146  1.8     uwe 				WSCOL_BLACK, /* bg */
    147  1.8     uwe 				0,           /* wsattrs */
    148  1.8     uwe 				&defattr);
    149  1.8     uwe 
    150  1.8     uwe 	wsdisplay_cnattach(&igsfb_stdscreen,
    151  1.8     uwe 			   ri,   /* emulcookie */
    152  1.8     uwe 			   0, 0, /* cursor position */
    153  1.8     uwe 			   defattr);
    154  1.8     uwe 	return (0);
    155  1.8     uwe }
    156  1.1     uwe 
    157  1.1     uwe 
    158  1.1     uwe /*
    159  1.1     uwe  * Finish off the attach.  Bus specific attach method should have
    160  1.8     uwe  * enabled io and memory accesses and mapped io (and cop?) registers.
    161  1.1     uwe  */
    162  1.1     uwe void
    163  1.8     uwe igsfb_attach_subr(sc, isconsole)
    164  1.1     uwe 	struct igsfb_softc *sc;
    165  1.1     uwe 	int isconsole;
    166  1.1     uwe {
    167  1.8     uwe 	struct igsfb_devconfig *dc = sc->sc_dc;
    168  1.8     uwe 	struct wsemuldisplaydev_attach_args waa;
    169  1.8     uwe 
    170  1.8     uwe 	KASSERT(dc != NULL);
    171  1.8     uwe 
    172  1.8     uwe 	if (!isconsole) {
    173  1.8     uwe 		igsfb_init_video(dc);
    174  1.8     uwe 		igsfb_init_wsdisplay(dc);
    175  1.8     uwe 	}
    176  1.8     uwe 
    177  1.8     uwe 	printf("%s: %dMB, %s%dx%d, %dbpp\n",
    178  1.8     uwe 	       sc->sc_dev.dv_xname,
    179  1.8     uwe 	       (u_int32_t)(dc->dc_vmemsz >> 20),
    180  1.8     uwe 	       (dc->dc_hwflags & IGSFB_HW_BSWAP)
    181  1.8     uwe 		   ? (dc->dc_hwflags & IGSFB_HW_BE_SELECT)
    182  1.8     uwe 		       ? "hardware bswap, " : "software bswap, "
    183  1.8     uwe 		   : "",
    184  1.8     uwe 	       dc->dc_width, dc->dc_height, dc->dc_depth);
    185  1.8     uwe 
    186  1.8     uwe 	/* attach wsdisplay */
    187  1.8     uwe 	waa.console = isconsole;
    188  1.8     uwe 	waa.scrdata = &igsfb_screenlist;
    189  1.8     uwe 	waa.accessops = &igsfb_accessops;
    190  1.8     uwe 	waa.accesscookie = dc;
    191  1.8     uwe 
    192  1.8     uwe 	config_found(&sc->sc_dev, &waa, wsemuldisplaydevprint);
    193  1.8     uwe }
    194  1.8     uwe 
    195  1.8     uwe 
    196  1.8     uwe static int
    197  1.8     uwe igsfb_init_video(dc)
    198  1.8     uwe 	struct igsfb_devconfig *dc;
    199  1.8     uwe {
    200  1.4     uwe 	bus_space_handle_t tmph;
    201  1.4     uwe 	u_int8_t *p;
    202  1.4     uwe 	int need_bswap;
    203  1.8     uwe 	bus_addr_t fbaddr, craddr;
    204  1.1     uwe 	off_t croffset;
    205  1.1     uwe 	u_int8_t busctl, curctl;
    206  1.1     uwe 
    207  1.8     uwe 	/* Total amount of video memory. */
    208  1.8     uwe 	busctl = igs_ext_read(dc->dc_iot, dc->dc_ioh, IGS_EXT_BUS_CTL);
    209  1.1     uwe 	if (busctl & 0x2)
    210  1.8     uwe 		dc->dc_vmemsz = 4;
    211  1.1     uwe 	else if (busctl & 0x1)
    212  1.8     uwe 		dc->dc_vmemsz = 2;
    213  1.1     uwe 	else
    214  1.8     uwe 		dc->dc_vmemsz = 1;
    215  1.8     uwe 	dc->dc_vmemsz <<= 20;	/* megabytes -> bytes */
    216  1.4     uwe 
    217  1.4     uwe 	/*
    218  1.8     uwe 	 * Check for endianness mismatch by writing a word at the end of
    219  1.8     uwe 	 * the video memory (off-screen) and reading it back byte-by-byte.
    220  1.4     uwe 	 */
    221  1.8     uwe 	if (bus_space_map(dc->dc_memt,
    222  1.8     uwe 			  dc->dc_memaddr + dc->dc_vmemsz - sizeof(u_int32_t),
    223  1.4     uwe 			  sizeof(u_int32_t),
    224  1.8     uwe 			  dc->dc_memflags | BUS_SPACE_MAP_LINEAR,
    225  1.4     uwe 			  &tmph) != 0)
    226  1.4     uwe 	{
    227  1.4     uwe 		printf("unable to map video memory for endianness test\n");
    228  1.8     uwe 		return (1);
    229  1.4     uwe 	}
    230  1.4     uwe 
    231  1.8     uwe 	p = bus_space_vaddr(dc->dc_memt, tmph);
    232  1.4     uwe #if BYTE_ORDER == BIG_ENDIAN
    233  1.4     uwe 	*((u_int32_t *)p) = 0x12345678;
    234  1.4     uwe #else
    235  1.4     uwe 	*((u_int32_t *)p) = 0x78563412;
    236  1.4     uwe #endif
    237  1.4     uwe 	if (p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78)
    238  1.4     uwe 		need_bswap = 0;
    239  1.4     uwe 	else
    240  1.4     uwe 		need_bswap = 1;
    241  1.4     uwe 
    242  1.8     uwe 	bus_space_unmap(dc->dc_memt, tmph, sizeof(u_int32_t));
    243  1.4     uwe 
    244  1.4     uwe 	/*
    245  1.4     uwe 	 * On CyberPro we can use magic bswap bit in linear address.
    246  1.4     uwe 	 */
    247  1.8     uwe 	fbaddr = dc->dc_memaddr;
    248  1.8     uwe 	if (need_bswap) {
    249  1.8     uwe 		dc->dc_hwflags |= IGSFB_HW_BSWAP;
    250  1.8     uwe 		if (dc->dc_id >= 0x2000) {
    251  1.8     uwe 			dc->dc_hwflags |= IGSFB_HW_BE_SELECT;
    252  1.4     uwe 			fbaddr |= IGS_MEM_BE_SELECT;
    253  1.4     uwe 		}
    254  1.8     uwe 	}
    255  1.8     uwe 
    256  1.8     uwe 	/*
    257  1.8     uwe 	 * XXX: TODO: make it possible to select the desired video mode.
    258  1.8     uwe 	 * For now - hardcode to 1024x768/8bpp.  This is what Krups OFW uses.
    259  1.8     uwe 	 */
    260  1.8     uwe 	igsfb_hw_setup(dc);
    261  1.8     uwe 
    262  1.8     uwe 	dc->dc_width = 1024;
    263  1.8     uwe 	dc->dc_height = 768;
    264  1.8     uwe 	dc->dc_depth = 8;
    265  1.1     uwe 
    266  1.1     uwe 	/*
    267  1.8     uwe 	 * Don't map in all N megs, just the amount we need for the wsscreen.
    268  1.1     uwe 	 */
    269  1.8     uwe 	dc->dc_fbsz = dc->dc_width * dc->dc_height; /* XXX: 8bpp specific */
    270  1.8     uwe 	if (bus_space_map(dc->dc_memt, fbaddr, dc->dc_fbsz,
    271  1.8     uwe 			  dc->dc_memflags | BUS_SPACE_MAP_LINEAR,
    272  1.8     uwe 			  &dc->dc_fbh) != 0)
    273  1.1     uwe 	{
    274  1.8     uwe 		bus_space_unmap(dc->dc_iot, dc->dc_ioh, IGS_REG_SIZE);
    275  1.1     uwe 		printf("unable to map framebuffer\n");
    276  1.8     uwe 		return (1);
    277  1.1     uwe 	}
    278  1.1     uwe 
    279  1.8     uwe 	igsfb_init_cmap(dc);
    280  1.8     uwe 
    281  1.1     uwe 	/*
    282  1.8     uwe 	 * 1KB for cursor sprite data at the very end of the video memory.
    283  1.1     uwe 	 */
    284  1.8     uwe 	croffset = dc->dc_vmemsz - IGS_CURSOR_DATA_SIZE;
    285  1.4     uwe 	craddr = fbaddr + croffset;
    286  1.8     uwe 	if (bus_space_map(dc->dc_memt, craddr, IGS_CURSOR_DATA_SIZE,
    287  1.8     uwe 			  dc->dc_memflags | BUS_SPACE_MAP_LINEAR,
    288  1.8     uwe 			  &dc->dc_crh) != 0)
    289  1.1     uwe 	{
    290  1.8     uwe 		bus_space_unmap(dc->dc_iot, dc->dc_ioh, IGS_REG_SIZE);
    291  1.8     uwe 		bus_space_unmap(dc->dc_memt, dc->dc_fbh, dc->dc_fbsz);
    292  1.1     uwe 		printf("unable to map cursor sprite region\n");
    293  1.8     uwe 		return (1);
    294  1.1     uwe 	}
    295  1.1     uwe 
    296  1.1     uwe 	/*
    297  1.8     uwe 	 * Tell the device where cursor sprite data are located in the
    298  1.8     uwe 	 * linear space (it takes data offset in 1KB units).
    299  1.1     uwe 	 */
    300  1.8     uwe 	croffset >>= 10;	/* bytes -> kilobytes */
    301  1.8     uwe 	igs_ext_write(dc->dc_iot, dc->dc_ioh,
    302  1.1     uwe 		      IGS_EXT_SPRITE_DATA_LO, croffset & 0xff);
    303  1.8     uwe 	igs_ext_write(dc->dc_iot, dc->dc_ioh,
    304  1.1     uwe 		      IGS_EXT_SPRITE_DATA_HI, (croffset >> 8) & 0xf);
    305  1.1     uwe 
    306  1.8     uwe 	/* init bit expanders for cursor sprite data */
    307  1.8     uwe 	igsfb_init_bit_tables(dc);
    308  1.8     uwe 
    309  1.8     uwe 	/* XXX: fill dc_cursor and use igsfb_update_cursor() instead? */
    310  1.8     uwe 	memset(&dc->dc_cursor, 0, sizeof(struct igs_hwcursor));
    311  1.8     uwe 	memset(bus_space_vaddr(dc->dc_memt, dc->dc_crh),
    312  1.8     uwe 	       /* transparent */ 0xaa, IGS_CURSOR_DATA_SIZE);
    313  1.1     uwe 
    314  1.8     uwe 	curctl = igs_ext_read(dc->dc_iot, dc->dc_ioh, IGS_EXT_SPRITE_CTL);
    315  1.1     uwe 	curctl |= IGS_EXT_SPRITE_64x64;
    316  1.1     uwe 	curctl &= ~IGS_EXT_SPRITE_VISIBLE;
    317  1.8     uwe 	igs_ext_write(dc->dc_iot, dc->dc_ioh, IGS_EXT_SPRITE_CTL, curctl);
    318  1.8     uwe 	dc->dc_curenb = 0;
    319  1.1     uwe 
    320  1.8     uwe 	/* make sure screen is not blanked */
    321  1.8     uwe 	dc->dc_blanked = 0;
    322  1.8     uwe 	igsfb_blank_screen(dc, dc->dc_blanked);
    323  1.1     uwe 
    324  1.8     uwe 	return (0);
    325  1.1     uwe }
    326  1.1     uwe 
    327  1.1     uwe 
    328  1.8     uwe static void
    329  1.8     uwe igsfb_init_cmap(dc)
    330  1.8     uwe 	struct igsfb_devconfig *dc;
    331  1.4     uwe {
    332  1.8     uwe 	bus_space_tag_t iot = dc->dc_iot;
    333  1.8     uwe 	bus_space_handle_t ioh = dc->dc_ioh;
    334  1.8     uwe 	const u_int8_t *p;
    335  1.8     uwe 	int i;
    336  1.4     uwe 
    337  1.8     uwe 	p = rasops_cmap;	/* "ANSI" color map */
    338  1.4     uwe 
    339  1.8     uwe 	/* init software copy */
    340  1.8     uwe 	for (i = 0; i < IGS_CMAP_SIZE; ++i, p += 3) {
    341  1.8     uwe 		dc->dc_cmap.r[i] = p[0];
    342  1.8     uwe 		dc->dc_cmap.g[i] = p[1];
    343  1.8     uwe 		dc->dc_cmap.b[i] = p[2];
    344  1.8     uwe 	}
    345  1.4     uwe 
    346  1.8     uwe 	/* propagate to the device */
    347  1.8     uwe 	igsfb_update_cmap(dc, 0, IGS_CMAP_SIZE);
    348  1.1     uwe 
    349  1.8     uwe 	/* set overscan color (XXX: use defattr's background) */
    350  1.8     uwe 	igs_ext_write(iot, ioh, IGS_EXT_OVERSCAN_RED,   0);
    351  1.8     uwe 	igs_ext_write(iot, ioh, IGS_EXT_OVERSCAN_GREEN, 0);
    352  1.8     uwe 	igs_ext_write(iot, ioh, IGS_EXT_OVERSCAN_BLUE,  0);
    353  1.1     uwe }
    354  1.1     uwe 
    355  1.8     uwe 
    356  1.1     uwe static void
    357  1.8     uwe igsfb_init_wsdisplay(dc)
    358  1.8     uwe 	struct igsfb_devconfig *dc;
    359  1.1     uwe {
    360  1.8     uwe 	struct rasops_info *ri;
    361  1.1     uwe 	int wsfcookie;
    362  1.1     uwe 
    363  1.8     uwe 	ri = &dc->dc_ri;
    364  1.8     uwe 	ri->ri_hw = dc;
    365  1.1     uwe 
    366  1.1     uwe 	ri->ri_flg = RI_CENTER | RI_CLEAR;
    367  1.8     uwe 	if (IGSFB_HW_SOFT_BSWAP(dc))
    368  1.1     uwe 	    ri->ri_flg |= RI_BSWAP;
    369  1.1     uwe 
    370  1.8     uwe 	ri->ri_depth = dc->dc_depth;
    371  1.8     uwe 	ri->ri_width = dc->dc_width;
    372  1.8     uwe 	ri->ri_height = dc->dc_height;
    373  1.6     uwe 
    374  1.8     uwe 	ri->ri_stride = dc->dc_width; /* XXX: 8bpp specific */
    375  1.8     uwe 	ri->ri_bits = (u_char *)dc->dc_fbh;
    376  1.1     uwe 
    377  1.1     uwe 	/*
    378  1.1     uwe 	 * Initialize wsfont related stuff.
    379  1.1     uwe 	 */
    380  1.1     uwe 	wsfont_init();
    381  1.1     uwe 
    382  1.1     uwe 	/* prefer gallant that is identical to the one the prom uses */
    383  1.1     uwe 	wsfcookie = wsfont_find("Gallant", 12, 22, 0,
    384  1.1     uwe 				WSDISPLAY_FONTORDER_L2R,
    385  1.1     uwe 				WSDISPLAY_FONTORDER_L2R);
    386  1.1     uwe 	if (wsfcookie <= 0) {
    387  1.1     uwe #ifdef DIAGNOSTIC
    388  1.8     uwe 		printf("unable to find font Gallant 12x22\n");
    389  1.1     uwe #endif
    390  1.8     uwe 		wsfcookie = wsfont_find(NULL, 0, 0, 0, /* any font at all? */
    391  1.1     uwe 					WSDISPLAY_FONTORDER_L2R,
    392  1.1     uwe 					WSDISPLAY_FONTORDER_L2R);
    393  1.1     uwe 	}
    394  1.1     uwe 
    395  1.1     uwe 	if (wsfcookie <= 0) {
    396  1.8     uwe 		printf("unable to find any fonts\n");
    397  1.1     uwe 		return;
    398  1.1     uwe 	}
    399  1.1     uwe 
    400  1.1     uwe 	if (wsfont_lock(wsfcookie, &ri->ri_font) != 0) {
    401  1.8     uwe 		printf("unable to lock font\n");
    402  1.1     uwe 		return;
    403  1.1     uwe 	}
    404  1.1     uwe 	ri->ri_wsfcookie = wsfcookie;
    405  1.1     uwe 
    406  1.1     uwe 
    407  1.8     uwe 	/* XXX: TODO: compute term size based on font dimensions. */
    408  1.1     uwe 	rasops_init(ri, 34, 80);
    409  1.1     uwe 
    410  1.1     uwe 	igsfb_stdscreen.nrows = ri->ri_rows;
    411  1.1     uwe 	igsfb_stdscreen.ncols = ri->ri_cols;
    412  1.1     uwe 	igsfb_stdscreen.textops = &ri->ri_ops;
    413  1.1     uwe 	igsfb_stdscreen.capabilities = ri->ri_caps;
    414  1.1     uwe }
    415  1.1     uwe 
    416  1.1     uwe 
    417  1.1     uwe /*
    418  1.8     uwe  * Spread a byte (abcd.efgh) into two (0a0b.0c0d 0e0f.0g0h).
    419  1.8     uwe  * Helper function for igsfb_init_bit_tables().
    420  1.8     uwe  */
    421  1.8     uwe static u_int16_t
    422  1.8     uwe igsfb_spread_bits_8(b)
    423  1.8     uwe 	u_int8_t b;
    424  1.8     uwe {
    425  1.8     uwe 	u_int16_t s = b;
    426  1.8     uwe 
    427  1.8     uwe 	s = ((s & 0x00f0) << 4) | (s & 0x000f);
    428  1.8     uwe 	s = ((s & 0x0c0c) << 2) | (s & 0x0303);
    429  1.8     uwe 	s = ((s & 0x2222) << 1) | (s & 0x1111);
    430  1.8     uwe 	return (s);
    431  1.8     uwe }
    432  1.8     uwe 
    433  1.8     uwe 
    434  1.8     uwe /*
    435  1.8     uwe  * Cursor sprite data are in 2bpp.  Incoming image/mask are in 1bpp.
    436  1.8     uwe  * Prebuild tables to expand 1bpp->2bpp, with bswapping if neccessary.
    437  1.8     uwe  */
    438  1.8     uwe static void
    439  1.8     uwe igsfb_init_bit_tables(dc)
    440  1.8     uwe 	struct igsfb_devconfig *dc;
    441  1.8     uwe {
    442  1.8     uwe 	struct igs_bittab *tab = &dc->dc_bittab;
    443  1.8     uwe 	int need_bswap = IGSFB_HW_SOFT_BSWAP(dc);
    444  1.8     uwe 	u_int i;
    445  1.8     uwe 
    446  1.8     uwe 	for (i = 0; i < 256; ++i) {
    447  1.8     uwe 		u_int16_t s = igsfb_spread_bits_8(i);
    448  1.8     uwe 
    449  1.8     uwe 		if (need_bswap)
    450  1.8     uwe 			s = bswap16(s);
    451  1.8     uwe 
    452  1.8     uwe 		tab->iexpand[i] = s;
    453  1.8     uwe 		tab->mexpand[i] = (s << 1) | s;	/* invariant over bswap16(s) */
    454  1.8     uwe 	}
    455  1.8     uwe }
    456  1.8     uwe 
    457  1.8     uwe 
    458  1.8     uwe /*
    459  1.1     uwe  * wsdisplay_accessops: mmap()
    460  1.4     uwe  *   XXX: allow mmapping i/o mapped i/o regs if INSECURE???
    461  1.1     uwe  */
    462  1.1     uwe static paddr_t
    463  1.1     uwe igsfb_mmap(v, offset, prot)
    464  1.1     uwe 	void *v;
    465  1.1     uwe 	off_t offset;
    466  1.1     uwe 	int prot;
    467  1.1     uwe {
    468  1.8     uwe 	struct igsfb_devconfig *dc = v;
    469  1.1     uwe 
    470  1.8     uwe 	if (offset >= dc->dc_memsz || offset < 0)
    471  1.1     uwe 		return (-1);
    472  1.1     uwe 
    473  1.8     uwe 	return (bus_space_mmap(dc->dc_memt, dc->dc_memaddr, offset, prot,
    474  1.8     uwe 			       dc->dc_memflags | BUS_SPACE_MAP_LINEAR));
    475  1.1     uwe }
    476  1.1     uwe 
    477  1.1     uwe 
    478  1.1     uwe /*
    479  1.1     uwe  * wsdisplay_accessops: ioctl()
    480  1.1     uwe  */
    481  1.1     uwe static int
    482  1.1     uwe igsfb_ioctl(v, cmd, data, flag, p)
    483  1.1     uwe 	void *v;
    484  1.1     uwe 	u_long cmd;
    485  1.1     uwe 	caddr_t data;
    486  1.1     uwe 	int flag;
    487  1.1     uwe 	struct proc *p;
    488  1.1     uwe {
    489  1.8     uwe 	struct igsfb_devconfig *dc = v;
    490  1.8     uwe 	struct rasops_info *ri;
    491  1.1     uwe 	int turnoff;
    492  1.1     uwe 
    493  1.1     uwe 	switch (cmd) {
    494  1.1     uwe 
    495  1.1     uwe 	case WSDISPLAYIO_GTYPE:
    496  1.1     uwe 		*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
    497  1.1     uwe 		return (0);
    498  1.1     uwe 
    499  1.1     uwe 	case WSDISPLAYIO_GINFO:
    500  1.8     uwe 		ri = &dc->dc_ri;
    501  1.1     uwe #define	wsd_fbip ((struct wsdisplay_fbinfo *)data)
    502  1.1     uwe 		wsd_fbip->height = ri->ri_height;
    503  1.1     uwe 		wsd_fbip->width = ri->ri_width;
    504  1.1     uwe 		wsd_fbip->depth = ri->ri_depth;
    505  1.1     uwe 		wsd_fbip->cmsize = IGS_CMAP_SIZE;
    506  1.1     uwe #undef wsd_fbip
    507  1.1     uwe 		return (0);
    508  1.1     uwe 
    509  1.1     uwe 	case WSDISPLAYIO_GVIDEO:
    510  1.8     uwe 		*(u_int *)data = dc->dc_blanked ?
    511  1.1     uwe 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    512  1.1     uwe 		return (0);
    513  1.1     uwe 
    514  1.1     uwe 	case WSDISPLAYIO_SVIDEO:
    515  1.1     uwe 		turnoff = (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF);
    516  1.8     uwe 		if (dc->dc_blanked != turnoff) {
    517  1.8     uwe 			dc->dc_blanked = turnoff;
    518  1.8     uwe 			igsfb_blank_screen(dc, dc->dc_blanked);
    519  1.1     uwe 		}
    520  1.1     uwe 		return (0);
    521  1.1     uwe 
    522  1.1     uwe 	case WSDISPLAYIO_GETCMAP:
    523  1.8     uwe 		return (igsfb_get_cmap(dc, (struct wsdisplay_cmap *)data));
    524  1.1     uwe 
    525  1.1     uwe 	case WSDISPLAYIO_PUTCMAP:
    526  1.8     uwe 		return (igsfb_set_cmap(dc, (struct wsdisplay_cmap *)data));
    527  1.1     uwe 
    528  1.1     uwe 	case WSDISPLAYIO_GCURMAX:
    529  1.1     uwe 		((struct wsdisplay_curpos *)data)->x = IGS_CURSOR_MAX_SIZE;
    530  1.1     uwe 		((struct wsdisplay_curpos *)data)->y = IGS_CURSOR_MAX_SIZE;
    531  1.1     uwe 		return (0);
    532  1.1     uwe 
    533  1.1     uwe 	case WSDISPLAYIO_GCURPOS:
    534  1.8     uwe 		*(struct wsdisplay_curpos *)data = dc->dc_cursor.cc_pos;
    535  1.1     uwe 		return (0);
    536  1.1     uwe 
    537  1.1     uwe 	case WSDISPLAYIO_SCURPOS:
    538  1.8     uwe 		igsfb_set_curpos(dc, (struct wsdisplay_curpos *)data);
    539  1.1     uwe 		return (0);
    540  1.1     uwe 
    541  1.1     uwe 	case WSDISPLAYIO_GCURSOR:
    542  1.8     uwe 		return (igsfb_get_cursor(dc, (struct wsdisplay_cursor *)data));
    543  1.1     uwe 
    544  1.1     uwe 	case WSDISPLAYIO_SCURSOR:
    545  1.8     uwe 		return (igsfb_set_cursor(dc, (struct wsdisplay_cursor *)data));
    546  1.1     uwe 	}
    547  1.1     uwe 
    548  1.1     uwe 	return (EPASSTHROUGH);
    549  1.1     uwe }
    550  1.1     uwe 
    551  1.1     uwe 
    552  1.1     uwe /*
    553  1.1     uwe  * wsdisplay_accessops: ioctl(WSDISPLAYIO_SVIDEO)
    554  1.1     uwe  */
    555  1.1     uwe static void
    556  1.8     uwe igsfb_blank_screen(dc, blank)
    557  1.8     uwe 	struct igsfb_devconfig *dc;
    558  1.1     uwe 	int blank;
    559  1.1     uwe {
    560  1.1     uwe 
    561  1.8     uwe 	igs_ext_write(dc->dc_iot, dc->dc_ioh,
    562  1.1     uwe 		      IGS_EXT_SYNC_CTL,
    563  1.1     uwe 		      blank ? IGS_EXT_SYNC_H0 | IGS_EXT_SYNC_V0
    564  1.1     uwe 			    : 0);
    565  1.1     uwe }
    566  1.1     uwe 
    567  1.1     uwe 
    568  1.1     uwe /*
    569  1.1     uwe  * wsdisplay_accessops: ioctl(WSDISPLAYIO_GETCMAP)
    570  1.8     uwe  *   Served from the software cmap copy.
    571  1.1     uwe  */
    572  1.1     uwe static int
    573  1.8     uwe igsfb_get_cmap(dc, p)
    574  1.8     uwe 	struct igsfb_devconfig *dc;
    575  1.1     uwe 	struct wsdisplay_cmap *p;
    576  1.1     uwe {
    577  1.1     uwe 	u_int index = p->index, count = p->count;
    578  1.1     uwe 
    579  1.5  itojun 	if (index >= IGS_CMAP_SIZE || count > IGS_CMAP_SIZE - index)
    580  1.1     uwe 		return (EINVAL);
    581  1.1     uwe 
    582  1.1     uwe 	if (!uvm_useracc(p->red, count, B_WRITE) ||
    583  1.1     uwe 	    !uvm_useracc(p->green, count, B_WRITE) ||
    584  1.1     uwe 	    !uvm_useracc(p->blue, count, B_WRITE))
    585  1.1     uwe 		return (EFAULT);
    586  1.1     uwe 
    587  1.8     uwe 	copyout(&dc->dc_cmap.r[index], p->red, count);
    588  1.8     uwe 	copyout(&dc->dc_cmap.g[index], p->green, count);
    589  1.8     uwe 	copyout(&dc->dc_cmap.b[index], p->blue, count);
    590  1.1     uwe 
    591  1.1     uwe 	return (0);
    592  1.1     uwe }
    593  1.1     uwe 
    594  1.1     uwe 
    595  1.1     uwe /*
    596  1.1     uwe  * wsdisplay_accessops: ioctl(WSDISPLAYIO_SETCMAP)
    597  1.8     uwe  *   Set the software cmap copy and propagate changed range to the device.
    598  1.1     uwe  */
    599  1.1     uwe static int
    600  1.8     uwe igsfb_set_cmap(dc, p)
    601  1.8     uwe 	struct igsfb_devconfig *dc;
    602  1.1     uwe 	struct wsdisplay_cmap *p;
    603  1.1     uwe {
    604  1.1     uwe 	u_int index = p->index, count = p->count;
    605  1.1     uwe 
    606  1.5  itojun 	if (index >= IGS_CMAP_SIZE || count > IGS_CMAP_SIZE - index)
    607  1.1     uwe 		return (EINVAL);
    608  1.1     uwe 
    609  1.1     uwe 	if (!uvm_useracc(p->red, count, B_READ) ||
    610  1.1     uwe 	    !uvm_useracc(p->green, count, B_READ) ||
    611  1.1     uwe 	    !uvm_useracc(p->blue, count, B_READ))
    612  1.1     uwe 		return (EFAULT);
    613  1.1     uwe 
    614  1.8     uwe 	copyin(p->red, &dc->dc_cmap.r[index], count);
    615  1.8     uwe 	copyin(p->green, &dc->dc_cmap.g[index], count);
    616  1.8     uwe 	copyin(p->blue, &dc->dc_cmap.b[index], count);
    617  1.1     uwe 
    618  1.8     uwe 	igsfb_update_cmap(dc, p->index, p->count);
    619  1.1     uwe 
    620  1.1     uwe 	return (0);
    621  1.1     uwe }
    622  1.1     uwe 
    623  1.1     uwe 
    624  1.1     uwe /*
    625  1.8     uwe  * Propagate specified part of the software cmap copy to the device.
    626  1.1     uwe  */
    627  1.1     uwe static void
    628  1.8     uwe igsfb_update_cmap(dc, index, count)
    629  1.8     uwe 	struct igsfb_devconfig *dc;
    630  1.1     uwe 	u_int index, count;
    631  1.1     uwe {
    632  1.1     uwe 	bus_space_tag_t t;
    633  1.1     uwe 	bus_space_handle_t h;
    634  1.1     uwe 	u_int last, i;
    635  1.1     uwe 
    636  1.1     uwe 	if (index >= IGS_CMAP_SIZE)
    637  1.1     uwe 		return;
    638  1.1     uwe 
    639  1.1     uwe 	last = index + count;
    640  1.1     uwe 	if (last > IGS_CMAP_SIZE)
    641  1.1     uwe 		last = IGS_CMAP_SIZE;
    642  1.1     uwe 
    643  1.8     uwe 	t = dc->dc_iot;
    644  1.8     uwe 	h = dc->dc_ioh;
    645  1.1     uwe 
    646  1.1     uwe 	/* start palette writing, index is autoincremented by hardware */
    647  1.1     uwe 	bus_space_write_1(t, h, IGS_DAC_PEL_WRITE_IDX, index);
    648  1.1     uwe 
    649  1.1     uwe 	for (i = index; i < last; ++i) {
    650  1.8     uwe 		bus_space_write_1(t, h, IGS_DAC_PEL_DATA, dc->dc_cmap.r[i]);
    651  1.8     uwe 		bus_space_write_1(t, h, IGS_DAC_PEL_DATA, dc->dc_cmap.g[i]);
    652  1.8     uwe 		bus_space_write_1(t, h, IGS_DAC_PEL_DATA, dc->dc_cmap.b[i]);
    653  1.1     uwe 	}
    654  1.1     uwe }
    655  1.1     uwe 
    656  1.1     uwe 
    657  1.1     uwe /*
    658  1.1     uwe  * wsdisplay_accessops: ioctl(WSDISPLAYIO_SCURPOS)
    659  1.1     uwe  */
    660  1.1     uwe static void
    661  1.8     uwe igsfb_set_curpos(dc, curpos)
    662  1.8     uwe 	struct igsfb_devconfig *dc;
    663  1.1     uwe 	struct wsdisplay_curpos *curpos;
    664  1.1     uwe {
    665  1.8     uwe 	struct rasops_info *ri = &dc->dc_ri;
    666  1.1     uwe 	int x = curpos->x, y = curpos->y;
    667  1.1     uwe 
    668  1.1     uwe 	if (y < 0)
    669  1.1     uwe 		y = 0;
    670  1.1     uwe 	else if (y > ri->ri_height)
    671  1.1     uwe 		y = ri->ri_height;
    672  1.1     uwe 	if (x < 0)
    673  1.1     uwe 		x = 0;
    674  1.1     uwe 	else if (x > ri->ri_width)
    675  1.1     uwe 		x = ri->ri_width;
    676  1.8     uwe 	dc->dc_cursor.cc_pos.x = x;
    677  1.8     uwe 	dc->dc_cursor.cc_pos.y = y;
    678  1.1     uwe 
    679  1.8     uwe 	igsfb_update_curpos(dc);
    680  1.1     uwe }
    681  1.1     uwe 
    682  1.1     uwe 
    683  1.1     uwe static void
    684  1.8     uwe igsfb_update_curpos(dc)
    685  1.8     uwe 	struct igsfb_devconfig *dc;
    686  1.1     uwe {
    687  1.1     uwe 	bus_space_tag_t t;
    688  1.1     uwe 	bus_space_handle_t h;
    689  1.1     uwe 	int x, xoff, y, yoff;
    690  1.1     uwe 
    691  1.1     uwe 	xoff = 0;
    692  1.8     uwe 	x = dc->dc_cursor.cc_pos.x - dc->dc_cursor.cc_hot.x;
    693  1.1     uwe 	if (x < 0) {
    694  1.8     uwe 		xoff = -x;
    695  1.1     uwe 		x = 0;
    696  1.1     uwe 	}
    697  1.1     uwe 
    698  1.1     uwe 	yoff = 0;
    699  1.8     uwe 	y = dc->dc_cursor.cc_pos.y - dc->dc_cursor.cc_hot.y;
    700  1.1     uwe 	if (y < 0) {
    701  1.8     uwe 		yoff = -y;
    702  1.1     uwe 		y = 0;
    703  1.1     uwe 	}
    704  1.1     uwe 
    705  1.8     uwe 	t = dc->dc_iot;
    706  1.8     uwe 	h = dc->dc_ioh;
    707  1.1     uwe 
    708  1.1     uwe 	igs_ext_write(t, h, IGS_EXT_SPRITE_HSTART_LO, x & 0xff);
    709  1.1     uwe 	igs_ext_write(t, h, IGS_EXT_SPRITE_HSTART_HI, (x >> 8) & 0x07);
    710  1.1     uwe 	igs_ext_write(t, h, IGS_EXT_SPRITE_HPRESET, xoff & 0x3f);
    711  1.1     uwe 
    712  1.1     uwe 	igs_ext_write(t, h, IGS_EXT_SPRITE_VSTART_LO, y & 0xff);
    713  1.1     uwe 	igs_ext_write(t, h, IGS_EXT_SPRITE_VSTART_HI, (y >> 8) & 0x07);
    714  1.1     uwe 	igs_ext_write(t, h, IGS_EXT_SPRITE_VPRESET, yoff & 0x3f);
    715  1.1     uwe }
    716  1.1     uwe 
    717  1.1     uwe 
    718  1.1     uwe /*
    719  1.1     uwe  * wsdisplay_accessops: ioctl(WSDISPLAYIO_GCURSOR)
    720  1.1     uwe  */
    721  1.1     uwe static int
    722  1.8     uwe igsfb_get_cursor(dc, p)
    723  1.8     uwe 	struct igsfb_devconfig *dc;
    724  1.1     uwe 	struct wsdisplay_cursor *p;
    725  1.1     uwe {
    726  1.1     uwe 
    727  1.1     uwe 	/* XXX: TODO */
    728  1.1     uwe 	return (0);
    729  1.1     uwe }
    730  1.1     uwe 
    731  1.1     uwe 
    732  1.1     uwe /*
    733  1.1     uwe  * wsdisplay_accessops: ioctl(WSDISPLAYIO_SCURSOR)
    734  1.1     uwe  */
    735  1.1     uwe static int
    736  1.8     uwe igsfb_set_cursor(dc, p)
    737  1.8     uwe 	struct igsfb_devconfig *dc;
    738  1.1     uwe 	struct wsdisplay_cursor *p;
    739  1.1     uwe {
    740  1.1     uwe 	struct igs_hwcursor *cc;
    741  1.1     uwe 	u_int v, index, count, icount, iwidth;
    742  1.1     uwe 
    743  1.8     uwe 	cc = &dc->dc_cursor;
    744  1.1     uwe 	v = p->which;
    745  1.1     uwe 
    746  1.1     uwe 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    747  1.1     uwe 		index = p->cmap.index;
    748  1.1     uwe 		count = p->cmap.count;
    749  1.1     uwe 		if (index >= 2 || (index + count) > 2)
    750  1.1     uwe 			return (EINVAL);
    751  1.1     uwe 		if (!uvm_useracc(p->cmap.red, count, B_READ)
    752  1.1     uwe 		    || !uvm_useracc(p->cmap.green, count, B_READ)
    753  1.1     uwe 		    || !uvm_useracc(p->cmap.blue, count, B_READ))
    754  1.1     uwe 			return (EFAULT);
    755  1.1     uwe 	}
    756  1.1     uwe 
    757  1.1     uwe 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    758  1.1     uwe 		if (p->size.x > IGS_CURSOR_MAX_SIZE
    759  1.1     uwe 		    || p->size.y > IGS_CURSOR_MAX_SIZE)
    760  1.1     uwe 			return (EINVAL);
    761  1.1     uwe 
    762  1.1     uwe 		iwidth = (p->size.x + 7) >> 3; /* bytes per scan line */
    763  1.1     uwe 		icount = iwidth * p->size.y;
    764  1.1     uwe 		if (!uvm_useracc(p->image, icount, B_READ)
    765  1.1     uwe 		    || !uvm_useracc(p->mask, icount, B_READ))
    766  1.1     uwe 			return (EFAULT);
    767  1.1     uwe 	}
    768  1.1     uwe 
    769  1.1     uwe 	/* XXX: verify that hot is within size, pos within screen? */
    770  1.1     uwe 
    771  1.1     uwe 	/* arguments verified, do the processing */
    772  1.1     uwe 
    773  1.1     uwe 	if (v & WSDISPLAY_CURSOR_DOCUR)
    774  1.8     uwe 		dc->dc_curenb = p->enable;
    775  1.1     uwe 
    776  1.1     uwe 	if (v & WSDISPLAY_CURSOR_DOPOS)
    777  1.1     uwe 		cc->cc_pos = p->pos;
    778  1.1     uwe 
    779  1.1     uwe 	if (v & WSDISPLAY_CURSOR_DOHOT)
    780  1.1     uwe 		cc->cc_hot = p->hot;
    781  1.1     uwe 
    782  1.1     uwe 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    783  1.1     uwe 		copyin(p->cmap.red, &cc->cc_color[index], count);
    784  1.1     uwe 		copyin(p->cmap.green, &cc->cc_color[index + 2], count);
    785  1.1     uwe 		copyin(p->cmap.blue, &cc->cc_color[index + 4], count);
    786  1.1     uwe 	}
    787  1.1     uwe 
    788  1.1     uwe 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    789  1.1     uwe 		u_int trailing_bits;
    790  1.1     uwe 
    791  1.1     uwe 		copyin(p->image, cc->cc_image, icount);
    792  1.1     uwe 		copyin(p->mask, cc->cc_mask, icount);
    793  1.1     uwe 		cc->cc_size = p->size;
    794  1.1     uwe 
    795  1.1     uwe 		/* clear trailing bits in the "partial" mask bytes */
    796  1.1     uwe 		trailing_bits = p->size.x & 0x07;
    797  1.1     uwe 		if (trailing_bits != 0) {
    798  1.1     uwe 			const u_int cutmask = ~((~0) << trailing_bits);
    799  1.1     uwe 			u_char *mp;
    800  1.1     uwe 			u_int i;
    801  1.1     uwe 
    802  1.1     uwe 			mp = cc->cc_mask + iwidth - 1;
    803  1.1     uwe 			for (i = 0; i < p->size.y; ++i) {
    804  1.1     uwe 				*mp &= cutmask;
    805  1.1     uwe 				mp += iwidth;
    806  1.1     uwe 			}
    807  1.1     uwe 		}
    808  1.8     uwe 		igsfb_convert_cursor_data(dc, iwidth, p->size.y);
    809  1.1     uwe 	}
    810  1.1     uwe 
    811  1.8     uwe 	igsfb_update_cursor(dc, v);
    812  1.1     uwe 	return (0);
    813  1.1     uwe }
    814  1.1     uwe 
    815  1.4     uwe 
    816  1.1     uwe /*
    817  1.1     uwe  * Convert incoming 1bpp cursor image/mask into native 2bpp format.
    818  1.1     uwe  */
    819  1.1     uwe static void
    820  1.8     uwe igsfb_convert_cursor_data(dc, w, h)
    821  1.8     uwe 	struct igsfb_devconfig *dc;
    822  1.1     uwe 	u_int w, h;
    823  1.1     uwe {
    824  1.8     uwe 	struct igs_hwcursor *cc = &dc->dc_cursor;
    825  1.8     uwe 	struct igs_bittab *btab = &dc->dc_bittab;
    826  1.1     uwe 	u_int8_t *ip, *mp;
    827  1.1     uwe 	u_int16_t *dp;
    828  1.1     uwe 	u_int line, i;
    829  1.1     uwe 
    830  1.1     uwe 	/* init sprite to be all transparent */
    831  1.1     uwe 	memset(cc->cc_sprite, 0xaa, IGS_CURSOR_DATA_SIZE);
    832  1.1     uwe 
    833  1.1     uwe 	/* first scanline */
    834  1.1     uwe 	ip = cc->cc_image;
    835  1.1     uwe 	mp = cc->cc_mask;
    836  1.1     uwe 	dp = cc->cc_sprite;
    837  1.1     uwe 
    838  1.1     uwe 	for (line = 0; line < h; ++line) {
    839  1.1     uwe 		for (i = 0; i < w; ++i) {
    840  1.8     uwe 			/* NB: tables are pre-bswapped if needed */
    841  1.1     uwe 			u_int16_t is = btab->iexpand[ip[i]];
    842  1.8     uwe 			u_int16_t ms = btab->iexpand[mp[i]]; /* NB: _I_ */
    843  1.1     uwe 
    844  1.8     uwe 			ms |= (ms << 1);
    845  1.1     uwe 			dp[i] = (0xaaaa & ~ms) | (is & ms);
    846  1.1     uwe 		}
    847  1.1     uwe 
    848  1.1     uwe 		/* next scanline */
    849  1.1     uwe 		ip += w;
    850  1.1     uwe 		mp += w;
    851  1.1     uwe 		dp += 8;	/* 2bpp, 8 pixels per short = 8 shorts */
    852  1.1     uwe 	}
    853  1.1     uwe }
    854  1.1     uwe 
    855  1.1     uwe 
    856  1.1     uwe /*
    857  1.8     uwe  * Propagate cursor changes to the device.
    858  1.8     uwe  * "which" is composed of WSDISPLAY_CURSOR_DO* bits.
    859  1.1     uwe  */
    860  1.1     uwe static void
    861  1.8     uwe igsfb_update_cursor(dc, which)
    862  1.8     uwe 	struct igsfb_devconfig *dc;
    863  1.1     uwe 	u_int which;
    864  1.1     uwe {
    865  1.8     uwe 	bus_space_tag_t iot = dc->dc_iot;
    866  1.8     uwe 	bus_space_handle_t ioh = dc->dc_ioh;
    867  1.1     uwe 	u_int8_t curctl;
    868  1.1     uwe 
    869  1.1     uwe 	/*
    870  1.1     uwe 	 * We will need to tweak sprite control register for cursor
    871  1.1     uwe 	 * visibility and cursor color map manipualtion.
    872  1.1     uwe 	 */
    873  1.1     uwe 	if (which & (WSDISPLAY_CURSOR_DOCUR | WSDISPLAY_CURSOR_DOCMAP)) {
    874  1.1     uwe 		curctl = igs_ext_read(iot, ioh, IGS_EXT_SPRITE_CTL);
    875  1.1     uwe 	}
    876  1.1     uwe 
    877  1.1     uwe 	if (which & WSDISPLAY_CURSOR_DOSHAPE) {
    878  1.8     uwe 		u_int8_t *dst = bus_space_vaddr(dc->dc_memt, dc->dc_crh);
    879  1.1     uwe 
    880  1.1     uwe 		/*
    881  1.1     uwe 		 * memcpy between spaces of different endianness would
    882  1.8     uwe 		 * be ... special.  We cannot be sure if memcpy gonna
    883  1.1     uwe 		 * push data in 4-byte chunks, we can't pre-bswap it,
    884  1.1     uwe 		 * so do it byte-by-byte to preserve byte ordering.
    885  1.1     uwe 		 */
    886  1.8     uwe 		if (IGSFB_HW_SOFT_BSWAP(dc)) {
    887  1.8     uwe 			u_int8_t *src = (u_int8_t *)dc->dc_cursor.cc_sprite;
    888  1.1     uwe 			int i;
    889  1.1     uwe 
    890  1.8     uwe 			for (i = 0; i < IGS_CURSOR_DATA_SIZE; ++i)
    891  1.1     uwe 				*dst++ = *src++;
    892  1.1     uwe 		} else {
    893  1.8     uwe 			memcpy(dst, dc->dc_cursor.cc_sprite,
    894  1.8     uwe 			       IGS_CURSOR_DATA_SIZE);
    895  1.1     uwe 		}
    896  1.1     uwe 	}
    897  1.1     uwe 
    898  1.1     uwe 	if (which & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
    899  1.1     uwe 		/* code shared with WSDISPLAYIO_SCURPOS */
    900  1.8     uwe 		igsfb_update_curpos(dc);
    901  1.1     uwe 	}
    902  1.1     uwe 
    903  1.1     uwe 	if (which & WSDISPLAY_CURSOR_DOCMAP) {
    904  1.1     uwe 		u_int8_t *p;
    905  1.1     uwe 
    906  1.1     uwe 		/* tell DAC we want access to the cursor palette */
    907  1.1     uwe 		igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
    908  1.4     uwe 			      curctl | IGS_EXT_SPRITE_DAC_PEL);
    909  1.1     uwe 
    910  1.8     uwe 		p = dc->dc_cursor.cc_color;
    911  1.1     uwe 
    912  1.1     uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_WRITE_IDX, 0);
    913  1.1     uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[0]);
    914  1.1     uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[2]);
    915  1.1     uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[4]);
    916  1.1     uwe 
    917  1.1     uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_WRITE_IDX, 1);
    918  1.1     uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[1]);
    919  1.1     uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[3]);
    920  1.1     uwe 		bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[5]);
    921  1.1     uwe 
    922  1.8     uwe 		/* restore access to the normal palette */
    923  1.1     uwe 		igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL, curctl);
    924  1.1     uwe 	}
    925  1.1     uwe 
    926  1.1     uwe 	if (which & WSDISPLAY_CURSOR_DOCUR) {
    927  1.1     uwe 		if ((curctl & IGS_EXT_SPRITE_VISIBLE) == 0
    928  1.8     uwe 		    && dc->dc_curenb)
    929  1.1     uwe 			igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
    930  1.1     uwe 				      curctl | IGS_EXT_SPRITE_VISIBLE);
    931  1.1     uwe 		else if ((curctl & IGS_EXT_SPRITE_VISIBLE) != 0
    932  1.8     uwe 			 && !dc->dc_curenb)
    933  1.1     uwe 			igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
    934  1.1     uwe 				      curctl & ~IGS_EXT_SPRITE_VISIBLE);
    935  1.1     uwe 	}
    936  1.1     uwe }
    937  1.1     uwe 
    938  1.1     uwe 
    939  1.1     uwe /*
    940  1.1     uwe  * wsdisplay_accessops: alloc_screen()
    941  1.1     uwe  */
    942  1.1     uwe static int
    943  1.1     uwe igsfb_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
    944  1.1     uwe 	void *v;
    945  1.1     uwe 	const struct wsscreen_descr *type;
    946  1.1     uwe 	void **cookiep;
    947  1.1     uwe 	int *curxp, *curyp;
    948  1.1     uwe 	long *attrp;
    949  1.1     uwe {
    950  1.8     uwe 	struct igsfb_devconfig *dc = v;
    951  1.8     uwe 	struct rasops_info *ri = &dc->dc_ri;
    952  1.7     uwe 
    953  1.8     uwe 	if (dc->dc_nscreens > 0) /* only do single screen for now */
    954  1.7     uwe 		return (ENOMEM);
    955  1.1     uwe 
    956  1.8     uwe 	dc->dc_nscreens = 1;
    957  1.7     uwe 
    958  1.8     uwe 	*cookiep = ri;		/* emulcookie for igsgfb_stdscreen.textops */
    959  1.8     uwe 	*curxp = *curyp = 0;	/* cursor position */
    960  1.8     uwe 	(*ri->ri_ops.allocattr)(ri,
    961  1.8     uwe 				WSCOL_BLACK, /* fg */
    962  1.8     uwe 				WSCOL_BLACK, /* bg */
    963  1.8     uwe 				0,           /* wsattr */
    964  1.8     uwe 				attrp);
    965  1.7     uwe 	return (0);
    966  1.1     uwe }
    967  1.1     uwe 
    968  1.1     uwe 
    969  1.1     uwe /*
    970  1.1     uwe  * wsdisplay_accessops: free_screen()
    971  1.1     uwe  */
    972  1.1     uwe static void
    973  1.1     uwe igsfb_free_screen(v, cookie)
    974  1.1     uwe 	void *v;
    975  1.1     uwe 	void *cookie;
    976  1.1     uwe {
    977  1.1     uwe 
    978  1.8     uwe 	/* XXX */
    979  1.1     uwe 	return;
    980  1.1     uwe }
    981  1.1     uwe 
    982  1.1     uwe 
    983  1.1     uwe /*
    984  1.1     uwe  * wsdisplay_accessops: show_screen()
    985  1.1     uwe  */
    986  1.1     uwe static int
    987  1.1     uwe igsfb_show_screen(v, cookie, waitok, cb, cbarg)
    988  1.1     uwe 	void *v;
    989  1.1     uwe 	void *cookie;
    990  1.1     uwe 	int waitok;
    991  1.1     uwe 	void (*cb)(void *, int, int);
    992  1.1     uwe 	void *cbarg;
    993  1.1     uwe {
    994  1.1     uwe 
    995  1.8     uwe 	/* XXX */
    996  1.1     uwe 	return (0);
    997  1.1     uwe }
    998