Home | History | Annotate | Line # | Download | only in gio
light.c revision 1.4.2.3
      1  1.4.2.3  yamt /*	$Id: light.c,v 1.4.2.3 2007/09/03 14:29:16 yamt Exp $	*/
      2  1.4.2.2  yamt 
      3  1.4.2.2  yamt /*
      4  1.4.2.2  yamt  * Copyright (c) 2006 Stephen M. Rumble
      5  1.4.2.2  yamt  * Copyright (c) 2003 Ilpo Ruotsalainen
      6  1.4.2.2  yamt  * All rights reserved.
      7  1.4.2.2  yamt  *
      8  1.4.2.2  yamt  * Redistribution and use in source and binary forms, with or without
      9  1.4.2.2  yamt  * modification, are permitted provided that the following conditions
     10  1.4.2.2  yamt  * are met:
     11  1.4.2.2  yamt  * 1. Redistributions of source code must retain the above copyright
     12  1.4.2.2  yamt  *    notice, this list of conditions and the following disclaimer.
     13  1.4.2.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.4.2.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     15  1.4.2.2  yamt  *    documentation and/or other materials provided with the distribution.
     16  1.4.2.2  yamt  * 3. The name of the author may not be used to endorse or promote products
     17  1.4.2.2  yamt  *    derived from this software without specific prior written permission.
     18  1.4.2.2  yamt  *
     19  1.4.2.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  1.4.2.2  yamt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  1.4.2.2  yamt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  1.4.2.2  yamt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  1.4.2.2  yamt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  1.4.2.2  yamt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  1.4.2.2  yamt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  1.4.2.2  yamt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  1.4.2.2  yamt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28  1.4.2.2  yamt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  1.4.2.2  yamt  *
     30  1.4.2.2  yamt  * <<Id: LICENSE_GC,v 1.1 2001/10/01 23:24:05 cgd Exp>>
     31  1.4.2.2  yamt  */
     32  1.4.2.2  yamt 
     33  1.4.2.2  yamt /*
     34  1.4.2.2  yamt  * SGI "Light" graphics, a.k.a. "Entry", "Starter", "LG1", and "LG2".
     35  1.4.2.2  yamt  *
     36  1.4.2.2  yamt  * 1024x768 8bpp at 60Hz.
     37  1.4.2.2  yamt  *
     38  1.4.2.2  yamt  * This driver supports the boards found in Indigo R3k and R4k machines.
     39  1.4.2.2  yamt  * There is a Crimson variant, but the register offsets differ significantly.
     40  1.4.2.2  yamt  *
     41  1.4.2.2  yamt  * Light's REX chip is the precursor of the REX3 found in "newport", hence
     42  1.4.2.2  yamt  * much similarity exists.
     43  1.4.2.2  yamt  */
     44  1.4.2.2  yamt 
     45  1.4.2.2  yamt #include <sys/cdefs.h>
     46  1.4.2.3  yamt __KERNEL_RCSID(0, "$NetBSD: light.c,v 1.4.2.3 2007/09/03 14:29:16 yamt Exp $");
     47  1.4.2.2  yamt 
     48  1.4.2.2  yamt #include <sys/param.h>
     49  1.4.2.2  yamt #include <sys/systm.h>
     50  1.4.2.2  yamt #include <sys/device.h>
     51  1.4.2.2  yamt #include <sys/malloc.h>
     52  1.4.2.2  yamt 
     53  1.4.2.2  yamt #include <machine/sysconf.h>
     54  1.4.2.2  yamt 
     55  1.4.2.2  yamt #include <dev/wscons/wsconsio.h>
     56  1.4.2.2  yamt #include <dev/wscons/wsdisplayvar.h>
     57  1.4.2.2  yamt #include <dev/wsfont/wsfont.h>
     58  1.4.2.2  yamt 
     59  1.4.2.2  yamt #include <sgimips/gio/giovar.h>
     60  1.4.2.2  yamt #include <sgimips/gio/lightvar.h>
     61  1.4.2.2  yamt #include <sgimips/gio/lightreg.h>
     62  1.4.2.2  yamt 
     63  1.4.2.2  yamt struct light_softc {
     64  1.4.2.2  yamt 	struct device sc_dev;
     65  1.4.2.2  yamt 
     66  1.4.2.2  yamt 	struct light_devconfig *sc_dc;
     67  1.4.2.2  yamt };
     68  1.4.2.2  yamt 
     69  1.4.2.2  yamt struct light_devconfig {
     70  1.4.2.2  yamt 	uint32_t		dc_addr;
     71  1.4.2.2  yamt 
     72  1.4.2.2  yamt 	bus_space_tag_t		dc_st;
     73  1.4.2.2  yamt 	bus_space_handle_t	dc_sh;
     74  1.4.2.2  yamt 
     75  1.4.2.2  yamt 	int			dc_boardrev;
     76  1.4.2.2  yamt 	int                     dc_font;
     77  1.4.2.2  yamt 	struct wsdisplay_font  *dc_fontdata;
     78  1.4.2.2  yamt };
     79  1.4.2.2  yamt 
     80  1.4.2.2  yamt /* always 1024x768x8 */
     81  1.4.2.2  yamt #define LIGHT_XRES	1024
     82  1.4.2.2  yamt #define LIGHT_YRES	768
     83  1.4.2.2  yamt #define LIGHT_DEPTH	8
     84  1.4.2.2  yamt 
     85  1.4.2.2  yamt static int	light_match(struct device *, struct cfdata *, void *);
     86  1.4.2.2  yamt static void	light_attach(struct device *, struct device *, void *);
     87  1.4.2.2  yamt 
     88  1.4.2.2  yamt CFATTACH_DECL(light, sizeof(struct light_softc), light_match, light_attach,
     89  1.4.2.2  yamt     NULL, NULL);
     90  1.4.2.2  yamt 
     91  1.4.2.2  yamt /* wsdisplay_emulops */
     92  1.4.2.2  yamt static void	light_cursor(void *, int, int, int);
     93  1.4.2.2  yamt static int	light_mapchar(void *, int, unsigned int *);
     94  1.4.2.2  yamt static void	light_putchar(void *, int, int, u_int, long);
     95  1.4.2.2  yamt static void	light_copycols(void *, int, int, int, int);
     96  1.4.2.2  yamt static void	light_erasecols(void *, int, int, int, long);
     97  1.4.2.2  yamt static void	light_copyrows(void *, int, int, int);
     98  1.4.2.2  yamt static void	light_eraserows(void *, int, int, long);
     99  1.4.2.2  yamt static int	light_allocattr(void *, int, int, int, long *);
    100  1.4.2.2  yamt 
    101  1.4.2.2  yamt /* wsdisplay_accessops */
    102  1.4.2.3  yamt static int	light_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    103  1.4.2.2  yamt static paddr_t	light_mmap(void *, void *, off_t, int);
    104  1.4.2.2  yamt static int	light_alloc_screen(void *, const struct wsscreen_descr *,
    105  1.4.2.2  yamt     void **, int *, int *, long *);
    106  1.4.2.2  yamt static void	light_free_screen(void *, void *);
    107  1.4.2.2  yamt static int	light_show_screen(void *, void *, int,
    108  1.4.2.2  yamt     void (*)(void *, int, int), void *);
    109  1.4.2.2  yamt 
    110  1.4.2.2  yamt static const struct wsdisplay_accessops light_accessops = {
    111  1.4.2.2  yamt 	.ioctl		= light_ioctl,
    112  1.4.2.2  yamt 	.mmap		= light_mmap,
    113  1.4.2.2  yamt 	.alloc_screen	= light_alloc_screen,
    114  1.4.2.2  yamt 	.free_screen	= light_free_screen,
    115  1.4.2.2  yamt 	.show_screen	= light_show_screen,
    116  1.4.2.2  yamt 	.load_font	= NULL,
    117  1.4.2.2  yamt 	.pollc		= NULL,
    118  1.4.2.2  yamt 	.scroll		= NULL
    119  1.4.2.2  yamt };
    120  1.4.2.2  yamt 
    121  1.4.2.2  yamt static const struct wsdisplay_emulops light_emulops = {
    122  1.4.2.2  yamt 	.cursor		= light_cursor,
    123  1.4.2.2  yamt 	.mapchar	= light_mapchar,
    124  1.4.2.2  yamt 	.putchar	= light_putchar,
    125  1.4.2.2  yamt 	.copycols	= light_copycols,
    126  1.4.2.2  yamt 	.erasecols	= light_erasecols,
    127  1.4.2.2  yamt 	.copyrows	= light_copyrows,
    128  1.4.2.2  yamt 	.eraserows	= light_eraserows,
    129  1.4.2.2  yamt 	.allocattr	= light_allocattr,
    130  1.4.2.2  yamt 	.replaceattr	= NULL
    131  1.4.2.2  yamt };
    132  1.4.2.2  yamt 
    133  1.4.2.2  yamt static const struct wsscreen_descr light_screen = {
    134  1.4.2.2  yamt 	.name           = "1024x768",
    135  1.4.2.2  yamt 	.ncols          = 128,
    136  1.4.2.2  yamt 	.nrows          = 48,
    137  1.4.2.2  yamt 	.textops        = &light_emulops,
    138  1.4.2.2  yamt 	.fontwidth      = 8,
    139  1.4.2.2  yamt 	.fontheight     = 16,
    140  1.4.2.2  yamt 	.capabilities   = WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_REVERSE
    141  1.4.2.2  yamt };
    142  1.4.2.2  yamt 
    143  1.4.2.2  yamt const struct wsscreen_descr *_light_screenlist[] = {
    144  1.4.2.2  yamt 	&light_screen
    145  1.4.2.2  yamt };
    146  1.4.2.2  yamt 
    147  1.4.2.2  yamt static const struct wsscreen_list light_screenlist = {
    148  1.4.2.2  yamt 	sizeof(_light_screenlist) / sizeof(_light_screenlist[0]),
    149  1.4.2.2  yamt 	_light_screenlist
    150  1.4.2.2  yamt };
    151  1.4.2.2  yamt 
    152  1.4.2.2  yamt static struct light_devconfig	light_console_dc;
    153  1.4.2.2  yamt static int			light_is_console = 0;
    154  1.4.2.2  yamt 
    155  1.4.2.2  yamt #define LIGHT_ATTR_ENCODE(fg, bg)	(((fg << 8) & 0xff00) | (bg * 0x00ff))
    156  1.4.2.2  yamt #define LIGHT_ATTR_FG(attr)		((attr >> 8) & 0x00ff)
    157  1.4.2.2  yamt #define LIGHT_ATTR_BG(attr)		(attr & 0x00ff)
    158  1.4.2.2  yamt 
    159  1.4.2.2  yamt #define LIGHT_IS_LG1(_rev)		((_rev) < 2)	/* else LG2 */
    160  1.4.2.2  yamt 
    161  1.4.2.2  yamt /*******************************************************************************
    162  1.4.2.2  yamt  * REX routines and helper functions
    163  1.4.2.2  yamt  ******************************************************************************/
    164  1.4.2.2  yamt 
    165  1.4.2.2  yamt static uint32_t
    166  1.4.2.2  yamt rex_read(struct light_devconfig *dc, uint32_t rset, uint32_t r)
    167  1.4.2.2  yamt {
    168  1.4.2.2  yamt 
    169  1.4.2.2  yamt 	return (bus_space_read_4(dc->dc_st, dc->dc_sh, rset + r));
    170  1.4.2.2  yamt }
    171  1.4.2.2  yamt 
    172  1.4.2.2  yamt static void
    173  1.4.2.2  yamt rex_write(struct light_devconfig *dc, uint32_t rset, uint32_t r, uint32_t v)
    174  1.4.2.2  yamt {
    175  1.4.2.2  yamt 
    176  1.4.2.2  yamt 	bus_space_write_4(dc->dc_st, dc->dc_sh, rset + r, v);
    177  1.4.2.2  yamt }
    178  1.4.2.2  yamt 
    179  1.4.2.2  yamt static uint8_t
    180  1.4.2.2  yamt rex_vc1_read(struct light_devconfig *dc)
    181  1.4.2.2  yamt {
    182  1.4.2.2  yamt 
    183  1.4.2.2  yamt 	rex_write(dc, REX_PAGE1_GO, REX_P1REG_CFGSEL, REX_CFGSEL_VC1_SYSCTL);
    184  1.4.2.2  yamt 	rex_read(dc, REX_PAGE1_GO, REX_P1REG_VC1_ADDRDATA);
    185  1.4.2.2  yamt 	return (rex_read(dc, REX_PAGE1_SET, REX_P1REG_VC1_ADDRDATA));
    186  1.4.2.2  yamt }
    187  1.4.2.2  yamt 
    188  1.4.2.2  yamt static void
    189  1.4.2.2  yamt rex_vc1_write(struct light_devconfig *dc, uint8_t val)
    190  1.4.2.2  yamt {
    191  1.4.2.2  yamt 
    192  1.4.2.2  yamt 	rex_write(dc, REX_PAGE1_GO, REX_P1REG_CFGSEL, REX_CFGSEL_VC1_SYSCTL);
    193  1.4.2.2  yamt 	rex_write(dc, REX_PAGE1_SET, REX_P1REG_VC1_ADDRDATA, val);
    194  1.4.2.2  yamt 	rex_write(dc, REX_PAGE1_GO, REX_P1REG_VC1_ADDRDATA, val);
    195  1.4.2.2  yamt }
    196  1.4.2.2  yamt 
    197  1.4.2.2  yamt static void
    198  1.4.2.2  yamt rex_wait(struct light_devconfig *dc)
    199  1.4.2.2  yamt {
    200  1.4.2.2  yamt 
    201  1.4.2.2  yamt 	while (rex_read(dc, REX_PAGE1_SET,REX_P1REG_CFGMODE) & REX_CFGMODE_BUSY)
    202  1.4.2.2  yamt 		;
    203  1.4.2.2  yamt }
    204  1.4.2.2  yamt 
    205  1.4.2.2  yamt static int
    206  1.4.2.2  yamt rex_revision(struct light_devconfig *dc)
    207  1.4.2.2  yamt {
    208  1.4.2.2  yamt 
    209  1.4.2.2  yamt 	rex_write(dc, REX_PAGE1_SET, REX_P1REG_CFGSEL, REX_CFGSEL_VC1_LADDR);
    210  1.4.2.2  yamt 	rex_read(dc, REX_PAGE1_GO, REX_P1REG_WCLOCKREV);
    211  1.4.2.2  yamt 	return (rex_read(dc, REX_PAGE1_SET, REX_P1REG_WCLOCKREV) & 0x7);
    212  1.4.2.2  yamt }
    213  1.4.2.2  yamt 
    214  1.4.2.2  yamt static void
    215  1.4.2.2  yamt rex_copy_rect(struct light_devconfig *dc, int from_x, int from_y, int to_x,
    216  1.4.2.2  yamt     int to_y, int width, int height)
    217  1.4.2.2  yamt {
    218  1.4.2.2  yamt 	int dx, dy, ystarti, yendi;
    219  1.4.2.2  yamt 
    220  1.4.2.2  yamt 	dx = from_x - to_x;
    221  1.4.2.2  yamt 	dy = from_y - to_y;
    222  1.4.2.2  yamt 
    223  1.4.2.2  yamt 	/* adjust for y. NB: STOPONX, STOPONY are inclusive */
    224  1.4.2.2  yamt 	if (to_y > from_y) {
    225  1.4.2.2  yamt 		ystarti = to_y + height - 1;
    226  1.4.2.2  yamt 		yendi = to_y;
    227  1.4.2.2  yamt 	} else {
    228  1.4.2.2  yamt 		ystarti = to_y;
    229  1.4.2.2  yamt 		yendi = to_y + height - 1;
    230  1.4.2.2  yamt 	}
    231  1.4.2.2  yamt 
    232  1.4.2.2  yamt 	rex_wait(dc);
    233  1.4.2.2  yamt 
    234  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_XSTARTI, to_x);
    235  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_XENDI, to_x + width);
    236  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_YSTARTI, ystarti);
    237  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_YENDI, yendi);
    238  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_COMMAND, REX_OP_DRAW |
    239  1.4.2.2  yamt 	    REX_LOGICOP_SRC | REX_OP_FLG_LOGICSRC | REX_OP_FLG_QUADMODE |
    240  1.4.2.2  yamt 	    REX_OP_FLG_BLOCK | REX_OP_FLG_STOPONX | REX_OP_FLG_STOPONY);
    241  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_GO, REX_P0REG_XYMOVE,
    242  1.4.2.2  yamt 	    ((dx << 16) & 0xffff0000) | (dy & 0x0000ffff));
    243  1.4.2.2  yamt }
    244  1.4.2.2  yamt 
    245  1.4.2.2  yamt static void
    246  1.4.2.2  yamt rex_fill_rect(struct light_devconfig *dc, int from_x, int from_y, int to_x,
    247  1.4.2.2  yamt     int to_y, long attr)
    248  1.4.2.2  yamt {
    249  1.4.2.2  yamt 
    250  1.4.2.2  yamt 	rex_wait(dc);
    251  1.4.2.2  yamt 
    252  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_YSTARTI, from_y);
    253  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_YENDI, to_y);
    254  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_XSTARTI, from_x);
    255  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_XENDI, to_x);
    256  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_COLORREDI, LIGHT_ATTR_BG(attr));
    257  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_COMMAND, REX_OP_DRAW |
    258  1.4.2.2  yamt 	    REX_LOGICOP_SRC | REX_OP_FLG_QUADMODE | REX_OP_FLG_BLOCK |
    259  1.4.2.2  yamt 	    REX_OP_FLG_STOPONX | REX_OP_FLG_STOPONY);
    260  1.4.2.2  yamt 	rex_read(dc, REX_PAGE0_GO, REX_P0REG_COMMAND);
    261  1.4.2.2  yamt }
    262  1.4.2.2  yamt 
    263  1.4.2.2  yamt /*******************************************************************************
    264  1.4.2.2  yamt  * match/attach functions
    265  1.4.2.2  yamt  ******************************************************************************/
    266  1.4.2.2  yamt 
    267  1.4.2.2  yamt static int
    268  1.4.2.2  yamt light_match(struct device *parent, struct cfdata *self, void *aux)
    269  1.4.2.2  yamt {
    270  1.4.2.2  yamt 	struct gio_attach_args *ga = aux;
    271  1.4.2.2  yamt 
    272  1.4.2.2  yamt 	if (ga->ga_addr != LIGHT_ADDR_0 && ga->ga_addr != LIGHT_ADDR_1)
    273  1.4.2.2  yamt 		return (0);
    274  1.4.2.2  yamt 
    275  1.4.2.2  yamt 	if (platform.badaddr(
    276  1.4.2.2  yamt 	    (void *)(ga->ga_ioh + REX_PAGE1_SET + REX_P1REG_XYOFFSET),
    277  1.4.2.2  yamt 	    sizeof(uint32_t)))
    278  1.4.2.2  yamt 		return (0);
    279  1.4.2.2  yamt 
    280  1.4.2.2  yamt 	if (bus_space_read_4(ga->ga_iot, ga->ga_ioh,
    281  1.4.2.2  yamt 	    REX_PAGE1_SET + REX_P1REG_XYOFFSET) != 0x08000800)
    282  1.4.2.2  yamt 		return (0);
    283  1.4.2.2  yamt 
    284  1.4.2.2  yamt 	return (1);
    285  1.4.2.2  yamt }
    286  1.4.2.2  yamt 
    287  1.4.2.2  yamt static void
    288  1.4.2.2  yamt light_attach_common(struct light_devconfig *dc, struct gio_attach_args *ga)
    289  1.4.2.2  yamt {
    290  1.4.2.2  yamt 
    291  1.4.2.2  yamt 	dc->dc_addr = ga->ga_addr;
    292  1.4.2.2  yamt 	dc->dc_st = ga->ga_iot;
    293  1.4.2.2  yamt 	dc->dc_sh = ga->ga_ioh;
    294  1.4.2.2  yamt 
    295  1.4.2.2  yamt 	dc->dc_boardrev = rex_revision(dc);
    296  1.4.2.2  yamt 
    297  1.4.2.2  yamt 	wsfont_init();
    298  1.4.2.2  yamt 
    299  1.4.2.2  yamt 	dc->dc_font = wsfont_find(NULL, 8, 16, 0, WSDISPLAY_FONTORDER_L2R,
    300  1.4.2.2  yamt 	    WSDISPLAY_FONTORDER_L2R);
    301  1.4.2.2  yamt 
    302  1.4.2.2  yamt 	if (dc->dc_font < 0)
    303  1.4.2.2  yamt 		panic("light_attach_common: no suitable fonts");
    304  1.4.2.2  yamt 
    305  1.4.2.2  yamt 	if (wsfont_lock(dc->dc_font, &dc->dc_fontdata))
    306  1.4.2.2  yamt 		panic("light_attach_common: unable to lock font data");
    307  1.4.2.2  yamt 
    308  1.4.2.2  yamt 	rex_vc1_write(dc, rex_vc1_read(dc) & ~(VC1_SYSCTL_CURSOR |
    309  1.4.2.2  yamt 	    VC1_SYSCTL_CURSOR_ON));
    310  1.4.2.2  yamt 	rex_fill_rect(dc, 0, 0, LIGHT_XRES - 1, LIGHT_YRES - 1, 0);
    311  1.4.2.2  yamt }
    312  1.4.2.2  yamt 
    313  1.4.2.2  yamt static void
    314  1.4.2.2  yamt light_attach(struct device *parent, struct device *self, void *aux)
    315  1.4.2.2  yamt {
    316  1.4.2.2  yamt 	struct gio_attach_args *ga = aux;
    317  1.4.2.2  yamt 	struct light_softc *sc = (void *)self;
    318  1.4.2.2  yamt 	struct wsemuldisplaydev_attach_args wa;
    319  1.4.2.2  yamt 
    320  1.4.2.2  yamt 	if (light_is_console && ga->ga_addr == light_console_dc.dc_addr) {
    321  1.4.2.2  yamt 		wa.console = 1;
    322  1.4.2.2  yamt 		sc->sc_dc = &light_console_dc;
    323  1.4.2.2  yamt 	} else {
    324  1.4.2.2  yamt 		wa.console = 0;
    325  1.4.2.2  yamt 		sc->sc_dc = malloc(sizeof(struct light_devconfig), M_DEVBUF,
    326  1.4.2.2  yamt 		    M_WAITOK | M_ZERO);
    327  1.4.2.2  yamt 		if (sc->sc_dc == NULL)
    328  1.4.2.2  yamt 			panic("light_attach: out of memory");
    329  1.4.2.2  yamt 
    330  1.4.2.2  yamt 		light_attach_common(sc->sc_dc, ga);
    331  1.4.2.2  yamt 	}
    332  1.4.2.2  yamt 
    333  1.4.2.2  yamt 	aprint_naive(": Display adapter\n");
    334  1.4.2.2  yamt 
    335  1.4.2.2  yamt 	aprint_normal(": SGI LG%d (board revision %d)\n",
    336  1.4.2.2  yamt 	    LIGHT_IS_LG1(sc->sc_dc->dc_boardrev) ? 1 : 2,
    337  1.4.2.2  yamt 	    sc->sc_dc->dc_boardrev);
    338  1.4.2.2  yamt 
    339  1.4.2.2  yamt 	wa.scrdata = &light_screenlist;
    340  1.4.2.2  yamt 	wa.accessops = &light_accessops;
    341  1.4.2.2  yamt 	wa.accesscookie = sc->sc_dc;
    342  1.4.2.2  yamt 
    343  1.4.2.2  yamt 	config_found(&sc->sc_dev, &wa, wsemuldisplaydevprint);
    344  1.4.2.2  yamt }
    345  1.4.2.2  yamt 
    346  1.4.2.2  yamt int
    347  1.4.2.2  yamt light_cnattach(struct gio_attach_args *ga)
    348  1.4.2.2  yamt {
    349  1.4.2.2  yamt 
    350  1.4.2.2  yamt 	if (!light_match(NULL, NULL, ga))
    351  1.4.2.2  yamt 		return (ENXIO);
    352  1.4.2.2  yamt 
    353  1.4.2.2  yamt 	light_attach_common(&light_console_dc, ga);
    354  1.4.2.2  yamt 
    355  1.4.2.2  yamt 	wsdisplay_cnattach(&light_screen, &light_console_dc, 0, 0,
    356  1.4.2.2  yamt 	    LIGHT_ATTR_ENCODE(WSCOL_WHITE, WSCOL_BLACK));
    357  1.4.2.2  yamt 
    358  1.4.2.2  yamt 	light_is_console = 1;
    359  1.4.2.2  yamt 
    360  1.4.2.2  yamt 	return (0);
    361  1.4.2.2  yamt }
    362  1.4.2.2  yamt 
    363  1.4.2.2  yamt /*******************************************************************************
    364  1.4.2.2  yamt  * wsdisplay_emulops
    365  1.4.2.2  yamt  ******************************************************************************/
    366  1.4.2.2  yamt 
    367  1.4.2.2  yamt static void
    368  1.4.2.2  yamt light_cursor(void *c, int on, int row, int col)
    369  1.4.2.2  yamt {
    370  1.4.2.2  yamt 	/* XXX */
    371  1.4.2.2  yamt }
    372  1.4.2.2  yamt 
    373  1.4.2.2  yamt static int
    374  1.4.2.2  yamt light_mapchar(void *c, int ch, unsigned int *cp)
    375  1.4.2.2  yamt {
    376  1.4.2.2  yamt 	struct light_devconfig *dc = (void *)c;
    377  1.4.2.2  yamt 
    378  1.4.2.2  yamt 	if (dc->dc_fontdata->encoding != WSDISPLAY_FONTENC_ISO) {
    379  1.4.2.2  yamt 		ch = wsfont_map_unichar(dc->dc_fontdata, ch);
    380  1.4.2.2  yamt 
    381  1.4.2.2  yamt 		if (ch < 0)
    382  1.4.2.2  yamt 			goto fail;
    383  1.4.2.2  yamt 	}
    384  1.4.2.2  yamt 
    385  1.4.2.2  yamt 	if (ch < dc->dc_fontdata->firstchar ||
    386  1.4.2.2  yamt 	    ch >= dc->dc_fontdata->firstchar + dc->dc_fontdata->numchars)
    387  1.4.2.2  yamt 		goto fail;
    388  1.4.2.2  yamt 
    389  1.4.2.2  yamt 	*cp = ch;
    390  1.4.2.2  yamt 	return 5;
    391  1.4.2.2  yamt 
    392  1.4.2.2  yamt fail:
    393  1.4.2.2  yamt 	*cp = ' ';
    394  1.4.2.2  yamt 	return 0;
    395  1.4.2.2  yamt }
    396  1.4.2.2  yamt 
    397  1.4.2.2  yamt static void
    398  1.4.2.2  yamt light_putchar(void *c, int row, int col, u_int ch, long attr)
    399  1.4.2.2  yamt {
    400  1.4.2.2  yamt         struct light_devconfig *dc = c;
    401  1.4.2.2  yamt 	struct wsdisplay_font *font = dc->dc_fontdata;
    402  1.4.2.2  yamt 	uint8_t *bitmap;
    403  1.4.2.2  yamt 	uint32_t pattern;
    404  1.4.2.2  yamt 	int i, x, y;
    405  1.4.2.2  yamt 
    406  1.4.2.2  yamt 	bitmap = (u_int8_t *)font->data +
    407  1.4.2.2  yamt 	    ((ch - font->firstchar) * font->fontheight * font->stride);
    408  1.4.2.2  yamt 	x = col * font->fontwidth;
    409  1.4.2.2  yamt 	y = row * font->fontheight;
    410  1.4.2.2  yamt 
    411  1.4.2.2  yamt 	rex_wait(dc);
    412  1.4.2.2  yamt 
    413  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_YSTARTI, y);
    414  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_YENDI, y + font->fontheight - 1);
    415  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_XSTARTI, x);
    416  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_XENDI, x + font->fontwidth - 1);
    417  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_COLORREDI, LIGHT_ATTR_FG(attr));
    418  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_COLORBACK, LIGHT_ATTR_BG(attr));
    419  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_GO,  REX_P0REG_COMMAND, REX_OP_NOP);
    420  1.4.2.2  yamt 
    421  1.4.2.2  yamt 	rex_wait(dc);
    422  1.4.2.2  yamt 
    423  1.4.2.2  yamt 	rex_write(dc, REX_PAGE0_SET, REX_P0REG_COMMAND, REX_OP_DRAW |
    424  1.4.2.2  yamt 	    REX_LOGICOP_SRC | REX_OP_FLG_ENZPATTERN | REX_OP_FLG_QUADMODE |
    425  1.4.2.2  yamt 	    REX_OP_FLG_XYCONTINUE | REX_OP_FLG_STOPONX | REX_OP_FLG_BLOCK |
    426  1.4.2.2  yamt 	    REX_OP_FLG_LENGTH32 | REX_OP_FLG_ZOPAQUE);
    427  1.4.2.2  yamt 
    428  1.4.2.2  yamt 	for (i = 0; i < font->fontheight; i++) {
    429  1.4.2.2  yamt 		/* XXX assumes font->fontwidth == 8 */
    430  1.4.2.2  yamt 		pattern = *bitmap << 24;
    431  1.4.2.2  yamt 		rex_write(dc, REX_PAGE0_GO, REX_P0REG_ZPATTERN, pattern);
    432  1.4.2.2  yamt 		bitmap += font->stride;
    433  1.4.2.2  yamt 	}
    434  1.4.2.2  yamt }
    435  1.4.2.2  yamt 
    436  1.4.2.2  yamt /* copy set of columns within the same line */
    437  1.4.2.2  yamt static void
    438  1.4.2.2  yamt light_copycols(void *c, int row, int srccol, int dstcol, int ncols)
    439  1.4.2.2  yamt {
    440  1.4.2.2  yamt 	struct light_devconfig *dc = c;
    441  1.4.2.2  yamt 	struct wsdisplay_font *font = dc->dc_fontdata;
    442  1.4.2.2  yamt 	int from_x, from_y, to_x, to_y, width, height;
    443  1.4.2.2  yamt 
    444  1.4.2.2  yamt 	from_x	= srccol * font->fontwidth;
    445  1.4.2.2  yamt 	from_y	= row * font->fontheight;
    446  1.4.2.2  yamt 	to_x	= dstcol * font->fontwidth;
    447  1.4.2.2  yamt 	to_y	= from_y;
    448  1.4.2.2  yamt 	width	= ncols * font->fontwidth;
    449  1.4.2.2  yamt 	height	= font->fontheight;
    450  1.4.2.2  yamt 
    451  1.4.2.2  yamt 	rex_copy_rect(c, from_x, from_y, to_x, to_y, width, height);
    452  1.4.2.2  yamt }
    453  1.4.2.2  yamt 
    454  1.4.2.2  yamt /* erase a set of columns in the same line */
    455  1.4.2.2  yamt static void
    456  1.4.2.2  yamt light_erasecols(void *c, int row, int startcol, int ncols, long attr)
    457  1.4.2.2  yamt {
    458  1.4.2.2  yamt 	struct light_devconfig *dc = c;
    459  1.4.2.2  yamt 	struct wsdisplay_font *font = dc->dc_fontdata;
    460  1.4.2.2  yamt 	int from_x, from_y, to_x, to_y;
    461  1.4.2.2  yamt 
    462  1.4.2.2  yamt 	from_x	= startcol * font->fontwidth;
    463  1.4.2.2  yamt 	from_y	= row * font->fontheight;
    464  1.4.2.2  yamt 	to_x	= from_x + (ncols * font->fontwidth) - 1;
    465  1.4.2.2  yamt 	to_y	= from_y + font->fontheight - 1;
    466  1.4.2.2  yamt 
    467  1.4.2.2  yamt 	rex_fill_rect(c, from_x, from_y, to_x, to_y, attr);
    468  1.4.2.2  yamt }
    469  1.4.2.2  yamt 
    470  1.4.2.2  yamt /* copy a set of complete rows */
    471  1.4.2.2  yamt static void
    472  1.4.2.2  yamt light_copyrows(void *c, int srcrow, int dstrow, int nrows)
    473  1.4.2.2  yamt {
    474  1.4.2.2  yamt 	struct light_devconfig *dc = c;
    475  1.4.2.2  yamt 	struct wsdisplay_font *font = dc->dc_fontdata;
    476  1.4.2.2  yamt 	int from_x, from_y, to_x, to_y, width, height;
    477  1.4.2.2  yamt 
    478  1.4.2.2  yamt 	from_x	= 0;
    479  1.4.2.2  yamt 	from_y	= srcrow * font->fontheight;
    480  1.4.2.2  yamt 	to_x	= 0;
    481  1.4.2.2  yamt 	to_y	= dstrow * font->fontheight;
    482  1.4.2.2  yamt 	width	= LIGHT_XRES;
    483  1.4.2.2  yamt 	height	= nrows * font->fontheight;
    484  1.4.2.2  yamt 
    485  1.4.2.2  yamt 	rex_copy_rect(c, from_x, from_y, to_x, to_y, width, height);
    486  1.4.2.2  yamt }
    487  1.4.2.2  yamt 
    488  1.4.2.2  yamt /* erase a set of complete rows */
    489  1.4.2.2  yamt static void
    490  1.4.2.2  yamt light_eraserows(void *c, int row, int nrows, long attr)
    491  1.4.2.2  yamt {
    492  1.4.2.2  yamt 	struct light_devconfig *dc = c;
    493  1.4.2.2  yamt 	struct wsdisplay_font *font = dc->dc_fontdata;
    494  1.4.2.2  yamt 	int from_x, from_y, to_x, to_y;
    495  1.4.2.2  yamt 
    496  1.4.2.2  yamt 	from_x	= 0;
    497  1.4.2.2  yamt 	from_y	= row * font->fontheight;
    498  1.4.2.2  yamt 	to_x	= LIGHT_XRES - 1;
    499  1.4.2.2  yamt 	to_y	= from_y + (nrows * font->fontheight) - 1;
    500  1.4.2.2  yamt 
    501  1.4.2.2  yamt 	rex_fill_rect(c, from_x, from_y, to_x, to_y, attr);
    502  1.4.2.2  yamt }
    503  1.4.2.2  yamt 
    504  1.4.2.2  yamt static int
    505  1.4.2.2  yamt light_allocattr(void *c, int fg, int bg, int flags, long *attr)
    506  1.4.2.2  yamt {
    507  1.4.2.2  yamt 
    508  1.4.2.2  yamt 	if (flags & ~(WSATTR_WSCOLORS | WSATTR_HILIT | WSATTR_REVERSE))
    509  1.4.2.2  yamt 		return (EINVAL);
    510  1.4.2.2  yamt 
    511  1.4.2.2  yamt 	if ((flags & WSATTR_WSCOLORS) == 0) {
    512  1.4.2.2  yamt 		fg = WSCOL_WHITE;
    513  1.4.2.2  yamt 		bg = WSCOL_BLACK;
    514  1.4.2.2  yamt 	}
    515  1.4.2.2  yamt 
    516  1.4.2.2  yamt 	if (flags & WSATTR_HILIT)
    517  1.4.2.2  yamt 		fg += 8;
    518  1.4.2.2  yamt 
    519  1.4.2.2  yamt 	if (flags & WSATTR_REVERSE) {
    520  1.4.2.2  yamt 		int tmp = fg;
    521  1.4.2.2  yamt 		fg = bg;
    522  1.4.2.2  yamt 		bg = tmp;
    523  1.4.2.2  yamt 	}
    524  1.4.2.2  yamt 
    525  1.4.2.2  yamt 	*attr = LIGHT_ATTR_ENCODE(fg, bg);
    526  1.4.2.2  yamt 	return (0);
    527  1.4.2.2  yamt }
    528  1.4.2.2  yamt 
    529  1.4.2.2  yamt /*******************************************************************************
    530  1.4.2.2  yamt  * wsdisplay_accessops
    531  1.4.2.2  yamt  ******************************************************************************/
    532  1.4.2.2  yamt 
    533  1.4.2.2  yamt static int
    534  1.4.2.3  yamt light_ioctl(void *c, void *vs, u_long cmd, void *data, int flag,
    535  1.4.2.2  yamt     struct lwp *l)
    536  1.4.2.2  yamt {
    537  1.4.2.2  yamt 	struct wsdisplay_fbinfo *fbinfo = (struct wsdisplay_fbinfo *)data;
    538  1.4.2.2  yamt 
    539  1.4.2.2  yamt 	switch (cmd) {
    540  1.4.2.2  yamt 	case WSDISPLAYIO_GINFO:
    541  1.4.2.2  yamt 		fbinfo->width	= LIGHT_XRES;
    542  1.4.2.2  yamt 		fbinfo->height	= LIGHT_YRES;
    543  1.4.2.2  yamt 		fbinfo->depth	= LIGHT_DEPTH;
    544  1.4.2.2  yamt 		fbinfo->cmsize	= 1 << LIGHT_DEPTH;
    545  1.4.2.2  yamt 		return (0);
    546  1.4.2.2  yamt 
    547  1.4.2.2  yamt 	case WSDISPLAYIO_GMODE:
    548  1.4.2.2  yamt 		*(u_int *)data = WSDISPLAYIO_MODE_EMUL;
    549  1.4.2.2  yamt 		break;
    550  1.4.2.2  yamt 
    551  1.4.2.2  yamt 	case WSDISPLAYIO_GTYPE:
    552  1.4.2.2  yamt 		*(u_int *)data = WSDISPLAY_TYPE_LIGHT;
    553  1.4.2.2  yamt 		return (0);
    554  1.4.2.2  yamt 
    555  1.4.2.2  yamt 	case WSDISPLAYIO_SVIDEO:
    556  1.4.2.2  yamt 		/*
    557  1.4.2.2  yamt 		 * Turning off VC1 will stop refreshing the video ram (or so I
    558  1.4.2.2  yamt 		 * suspect). We'll blank the screen after bringing it back up,
    559  1.4.2.2  yamt 		 * since that's nicer than displaying garbage.
    560  1.4.2.2  yamt 		 */
    561  1.4.2.2  yamt 		if (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF)
    562  1.4.2.2  yamt 			rex_vc1_write(c,rex_vc1_read(c) & ~VC1_SYSCTL_VIDEO_ON);
    563  1.4.2.2  yamt 		else {
    564  1.4.2.2  yamt 			rex_vc1_write(c, rex_vc1_read(c) | VC1_SYSCTL_VIDEO_ON);
    565  1.4.2.2  yamt 			rex_fill_rect(c, 0, 0, LIGHT_XRES-1, LIGHT_YRES-1, 0);
    566  1.4.2.2  yamt 		}
    567  1.4.2.2  yamt 		return (0);
    568  1.4.2.2  yamt 	}
    569  1.4.2.2  yamt 
    570  1.4.2.2  yamt 	return (EPASSTHROUGH);
    571  1.4.2.2  yamt }
    572  1.4.2.2  yamt 
    573  1.4.2.2  yamt static paddr_t
    574  1.4.2.2  yamt light_mmap(void *c, void *vs, off_t off, int prot)
    575  1.4.2.2  yamt {
    576  1.4.2.2  yamt         struct light_devconfig *dc = c;
    577  1.4.2.2  yamt 
    578  1.4.2.2  yamt 	if (off >= 0x7fff)
    579  1.4.2.2  yamt 		return (-1);
    580  1.4.2.2  yamt 
    581  1.4.2.2  yamt 	return (mips_btop(dc->dc_addr + off));
    582  1.4.2.2  yamt }
    583  1.4.2.2  yamt 
    584  1.4.2.2  yamt static int
    585  1.4.2.2  yamt light_alloc_screen(void *c, const struct wsscreen_descr *type, void **cookiep,
    586  1.4.2.2  yamt     int *curxp, int *curyp, long *attr)
    587  1.4.2.2  yamt {
    588  1.4.2.2  yamt 
    589  1.4.2.2  yamt 	return (ENOMEM);
    590  1.4.2.2  yamt }
    591  1.4.2.2  yamt 
    592  1.4.2.2  yamt static void
    593  1.4.2.2  yamt light_free_screen(void *c, void *cookie)
    594  1.4.2.2  yamt {
    595  1.4.2.2  yamt 
    596  1.4.2.2  yamt 	panic("light_free_screen");
    597  1.4.2.2  yamt }
    598  1.4.2.2  yamt 
    599  1.4.2.2  yamt static int
    600  1.4.2.2  yamt light_show_screen(void *c, void *cookie, int waitok,
    601  1.4.2.2  yamt     void (*cb)(void *, int, int), void *cbarg)
    602  1.4.2.2  yamt {
    603  1.4.2.2  yamt 
    604  1.4.2.2  yamt 	return (0);
    605  1.4.2.2  yamt }
    606