Home | History | Annotate | Line # | Download | only in gio
grtwo.c revision 1.8
      1  1.8  rumble /* $NetBSD: grtwo.c,v 1.8 2006/12/28 22:10:05 rumble Exp $	 */
      2  1.1  sekiya 
      3  1.1  sekiya /*
      4  1.1  sekiya  * Copyright (c) 2004 Christopher SEKIYA
      5  1.1  sekiya  * All rights reserved.
      6  1.1  sekiya  *
      7  1.1  sekiya  * Redistribution and use in source and binary forms, with or without
      8  1.1  sekiya  * modification, are permitted provided that the following conditions
      9  1.1  sekiya  * are met:
     10  1.1  sekiya  * 1. Redistributions of source code must retain the above copyright
     11  1.1  sekiya  *    notice, this list of conditions and the following disclaimer.
     12  1.1  sekiya  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  sekiya  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  sekiya  *    documentation and/or other materials provided with the distribution.
     15  1.1  sekiya  * 3. The name of the author may not be used to endorse or promote products
     16  1.1  sekiya  *    derived from this software without specific prior written permission.
     17  1.1  sekiya  *
     18  1.1  sekiya  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1  sekiya  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1  sekiya  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1  sekiya  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1  sekiya  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.1  sekiya  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.1  sekiya  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.1  sekiya  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.1  sekiya  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.1  sekiya  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1  sekiya  *
     29  1.1  sekiya  * <<Id: LICENSE_GC,v 1.1 2001/10/01 23:24:05 cgd Exp>>
     30  1.1  sekiya  */
     31  1.1  sekiya 
     32  1.1  sekiya /* wscons driver for SGI GR2 family of framebuffers
     33  1.1  sekiya  *
     34  1.1  sekiya  * Heavily based on the newport wscons driver.
     35  1.1  sekiya  */
     36  1.1  sekiya 
     37  1.1  sekiya #include <sys/cdefs.h>
     38  1.8  rumble __KERNEL_RCSID(0, "$NetBSD: grtwo.c,v 1.8 2006/12/28 22:10:05 rumble Exp $");
     39  1.1  sekiya 
     40  1.1  sekiya #include <sys/param.h>
     41  1.1  sekiya #include <sys/systm.h>
     42  1.1  sekiya #include <sys/device.h>
     43  1.1  sekiya #include <sys/malloc.h>
     44  1.1  sekiya 
     45  1.1  sekiya #include <dev/wscons/wsconsio.h>
     46  1.1  sekiya #include <dev/wscons/wsdisplayvar.h>
     47  1.1  sekiya #include <dev/wsfont/wsfont.h>
     48  1.1  sekiya 
     49  1.1  sekiya #include <sgimips/gio/giovar.h>
     50  1.1  sekiya #include <sgimips/gio/grtwovar.h>
     51  1.1  sekiya #include <sgimips/gio/grtworeg.h>
     52  1.1  sekiya 
     53  1.1  sekiya #include <sgimips/dev/int2var.h>
     54  1.1  sekiya 
     55  1.1  sekiya struct grtwo_softc {
     56  1.1  sekiya 	struct device   sc_dev;
     57  1.1  sekiya 
     58  1.1  sekiya 	struct grtwo_devconfig *sc_dc;
     59  1.1  sekiya };
     60  1.1  sekiya 
     61  1.1  sekiya struct grtwo_devconfig {
     62  1.1  sekiya 	u_int32_t        dc_addr;
     63  1.1  sekiya 
     64  1.1  sekiya 	bus_space_tag_t iot;
     65  1.1  sekiya 	bus_space_handle_t ioh;
     66  1.1  sekiya 
     67  1.1  sekiya 	u_int8_t	boardrev;
     68  1.1  sekiya 	u_int8_t	backendrev;
     69  1.1  sekiya 	int             hq2rev;
     70  1.1  sekiya 	int             ge7rev;
     71  1.1  sekiya 	int             vc1rev;
     72  1.1  sekiya 	int             zbuffer;
     73  1.1  sekiya 	int             cmaprev;
     74  1.1  sekiya 	int             xmaprev;
     75  1.1  sekiya 	int             rexrev;
     76  1.1  sekiya 	int             xres;
     77  1.1  sekiya 	int             yres;
     78  1.1  sekiya 	int             depth;
     79  1.1  sekiya 	int             monitor;
     80  1.1  sekiya 
     81  1.1  sekiya 	int             dc_font;
     82  1.1  sekiya 	struct wsdisplay_font *dc_fontdata;
     83  1.1  sekiya };
     84  1.1  sekiya 
     85  1.1  sekiya static int      grtwo_match(struct device *, struct cfdata *, void *);
     86  1.1  sekiya static void     grtwo_attach(struct device *, struct device *, void *);
     87  1.1  sekiya 
     88  1.1  sekiya CFATTACH_DECL(grtwo, sizeof(struct grtwo_softc),
     89  1.1  sekiya 	      grtwo_match, grtwo_attach, NULL, NULL);
     90  1.1  sekiya 
     91  1.1  sekiya /* textops */
     92  1.1  sekiya static void     grtwo_cursor(void *, int, int, int);
     93  1.1  sekiya static int      grtwo_mapchar(void *, int, unsigned int *);
     94  1.1  sekiya static void     grtwo_putchar(void *, int, int, u_int, long);
     95  1.1  sekiya static void     grtwo_copycols(void *, int, int, int, int);
     96  1.1  sekiya static void     grtwo_erasecols(void *, int, int, int, long);
     97  1.1  sekiya static void     grtwo_copyrows(void *, int, int, int);
     98  1.1  sekiya static void     grtwo_eraserows(void *, int, int, long);
     99  1.1  sekiya static int      grtwo_allocattr(void *, int, int, int, long *);
    100  1.1  sekiya 
    101  1.1  sekiya /* accessops */
    102  1.7    jmmv static int      grtwo_ioctl(void *, void *, u_long, caddr_t, int, struct lwp *);
    103  1.7    jmmv static paddr_t  grtwo_mmap(void *, void *, off_t, int);
    104  1.1  sekiya static int
    105  1.1  sekiya grtwo_alloc_screen(void *, const struct wsscreen_descr *,
    106  1.1  sekiya 		   void **, int *, int *, long *);
    107  1.1  sekiya static void     grtwo_free_screen(void *, void *);
    108  1.1  sekiya static int
    109  1.1  sekiya                 grtwo_show_screen(void *, void *, int, void (*) (void *, int, int), void *);
    110  1.1  sekiya 
    111  1.2  sekiya static int	grtwo_intr0(void *);
    112  1.2  sekiya static int	grtwo_intr6(void *);
    113  1.2  sekiya 
    114  1.1  sekiya static const struct wsdisplay_emulops grtwo_textops = {
    115  1.1  sekiya 	.cursor = grtwo_cursor,
    116  1.1  sekiya 	.mapchar = grtwo_mapchar,
    117  1.1  sekiya 	.putchar = grtwo_putchar,
    118  1.1  sekiya 	.copycols = grtwo_copycols,
    119  1.1  sekiya 	.erasecols = grtwo_erasecols,
    120  1.1  sekiya 	.copyrows = grtwo_copyrows,
    121  1.1  sekiya 	.eraserows = grtwo_eraserows,
    122  1.1  sekiya 	.allocattr = grtwo_allocattr
    123  1.1  sekiya };
    124  1.1  sekiya 
    125  1.1  sekiya static const struct wsdisplay_accessops grtwo_accessops = {
    126  1.1  sekiya 	.ioctl = grtwo_ioctl,
    127  1.1  sekiya 	.mmap = grtwo_mmap,
    128  1.1  sekiya 	.alloc_screen = grtwo_alloc_screen,
    129  1.1  sekiya 	.free_screen = grtwo_free_screen,
    130  1.1  sekiya 	.show_screen = grtwo_show_screen,
    131  1.1  sekiya };
    132  1.1  sekiya 
    133  1.1  sekiya static const struct wsscreen_descr grtwo_screen = {
    134  1.1  sekiya 	.name = "1280x1024",
    135  1.1  sekiya 	.ncols = 160,
    136  1.2  sekiya 	.nrows = 64, /* 40 */
    137  1.1  sekiya 	.textops = &grtwo_textops,
    138  1.1  sekiya 	.fontwidth = 8,
    139  1.1  sekiya 	.fontheight = 16,
    140  1.1  sekiya 	.capabilities = WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_REVERSE
    141  1.1  sekiya };
    142  1.1  sekiya 
    143  1.1  sekiya static const struct wsscreen_descr *_grtwo_screenlist[] = {
    144  1.1  sekiya 	&grtwo_screen
    145  1.1  sekiya };
    146  1.1  sekiya 
    147  1.1  sekiya static const struct wsscreen_list grtwo_screenlist = {
    148  1.1  sekiya 	sizeof(_grtwo_screenlist) / sizeof(struct wsscreen_descr *),
    149  1.1  sekiya 	_grtwo_screenlist
    150  1.1  sekiya };
    151  1.1  sekiya 
    152  1.1  sekiya static struct grtwo_devconfig grtwo_console_dc;
    153  1.1  sekiya static int      grtwo_is_console = 0;
    154  1.1  sekiya 
    155  1.1  sekiya #define GR2_ATTR_ENCODE(fg,bg)	(((fg) << 8) | (bg))
    156  1.1  sekiya #define GR2_ATTR_BG(a)		((a) & 0xff)
    157  1.1  sekiya #define GR2_ATTR_FG(a)		(((a) >> 8) & 0xff)
    158  1.1  sekiya 
    159  1.1  sekiya static const u_int16_t grtwo_cursor_data[128] = {
    160  1.1  sekiya 	/* Bit 0 */
    161  1.1  sekiya 	0xff00, 0x0000,
    162  1.1  sekiya 	0xff00, 0x0000,
    163  1.1  sekiya 	0xff00, 0x0000,
    164  1.1  sekiya 	0xff00, 0x0000,
    165  1.1  sekiya 	0xff00, 0x0000,
    166  1.1  sekiya 	0xff00, 0x0000,
    167  1.1  sekiya 	0xff00, 0x0000,
    168  1.1  sekiya 	0xff00, 0x0000,
    169  1.1  sekiya 	0xff00, 0x0000,
    170  1.1  sekiya 	0xff00, 0x0000,
    171  1.1  sekiya 	0xff00, 0x0000,
    172  1.1  sekiya 	0xff00, 0x0000,
    173  1.1  sekiya 	0xff00, 0x0000,
    174  1.1  sekiya 	0xff00, 0x0000,
    175  1.1  sekiya 	0xff00, 0x0000,
    176  1.1  sekiya 	0xff00, 0x0000,
    177  1.1  sekiya 	0x0000, 0x0000,
    178  1.1  sekiya 	0x0000, 0x0000,
    179  1.1  sekiya 	0x0000, 0x0000,
    180  1.1  sekiya 	0x0000, 0x0000,
    181  1.1  sekiya 	0x0000, 0x0000,
    182  1.1  sekiya 	0x0000, 0x0000,
    183  1.1  sekiya 	0x0000, 0x0000,
    184  1.1  sekiya 	0x0000, 0x0000,
    185  1.1  sekiya 	0x0000, 0x0000,
    186  1.1  sekiya 	0x0000, 0x0000,
    187  1.1  sekiya 	0x0000, 0x0000,
    188  1.1  sekiya 	0x0000, 0x0000,
    189  1.1  sekiya 	0x0000, 0x0000,
    190  1.1  sekiya 	0x0000, 0x0000,
    191  1.1  sekiya 	0x0000, 0x0000,
    192  1.1  sekiya 	0x0000, 0x0000,
    193  1.1  sekiya 
    194  1.1  sekiya 	/* Bit 1 */
    195  1.1  sekiya 	0x0000, 0x0000,
    196  1.1  sekiya 	0x0000, 0x0000,
    197  1.1  sekiya 	0x0000, 0x0000,
    198  1.1  sekiya 	0x0000, 0x0000,
    199  1.1  sekiya 	0x0000, 0x0000,
    200  1.1  sekiya 	0x0000, 0x0000,
    201  1.1  sekiya 	0x0000, 0x0000,
    202  1.1  sekiya 	0x0000, 0x0000,
    203  1.1  sekiya 	0x0000, 0x0000,
    204  1.1  sekiya 	0x0000, 0x0000,
    205  1.1  sekiya 	0x0000, 0x0000,
    206  1.1  sekiya 	0x0000, 0x0000,
    207  1.1  sekiya 	0x0000, 0x0000,
    208  1.1  sekiya 	0x0000, 0x0000,
    209  1.1  sekiya 	0x0000, 0x0000,
    210  1.1  sekiya 	0x0000, 0x0000,
    211  1.1  sekiya 	0x0000, 0x0000,
    212  1.1  sekiya 	0x0000, 0x0000,
    213  1.1  sekiya 	0x0000, 0x0000,
    214  1.1  sekiya 	0x0000, 0x0000,
    215  1.1  sekiya 	0x0000, 0x0000,
    216  1.1  sekiya 	0x0000, 0x0000,
    217  1.1  sekiya 	0x0000, 0x0000,
    218  1.1  sekiya 	0x0000, 0x0000,
    219  1.1  sekiya 	0x0000, 0x0000,
    220  1.1  sekiya 	0x0000, 0x0000,
    221  1.1  sekiya 	0x0000, 0x0000,
    222  1.1  sekiya 	0x0000, 0x0000,
    223  1.1  sekiya 	0x0000, 0x0000,
    224  1.1  sekiya 	0x0000, 0x0000,
    225  1.1  sekiya 	0x0000, 0x0000,
    226  1.1  sekiya 	0x0000, 0x0000,
    227  1.1  sekiya };
    228  1.1  sekiya 
    229  1.1  sekiya static const u_int8_t grtwo_defcmap[8 * 3] = {
    230  1.1  sekiya 	/* Normal colors */
    231  1.1  sekiya 	0x00, 0x00, 0x00,	/* black */
    232  1.1  sekiya 	0x7f, 0x00, 0x00,	/* red */
    233  1.1  sekiya 	0x00, 0x7f, 0x00,	/* green */
    234  1.1  sekiya 	0x7f, 0x7f, 0x00,	/* brown */
    235  1.1  sekiya 	0x00, 0x00, 0x7f,	/* blue */
    236  1.1  sekiya 	0x7f, 0x00, 0x7f,	/* magenta */
    237  1.1  sekiya 	0x00, 0x7f, 0x7f,	/* cyan */
    238  1.1  sekiya 	0xc7, 0xc7, 0xc7,	/* white - XXX too dim? */
    239  1.1  sekiya };
    240  1.1  sekiya 
    241  1.1  sekiya static void
    242  1.1  sekiya grtwo_wait_gfifo(struct grtwo_devconfig * dc)
    243  1.1  sekiya {
    244  1.1  sekiya 	int2_wait_fifo(1);
    245  1.1  sekiya }
    246  1.1  sekiya 
    247  1.2  sekiya static inline void
    248  1.2  sekiya grtwo_set_color(bus_space_tag_t iot, bus_space_handle_t ioh, int color)
    249  1.2  sekiya {
    250  1.2  sekiya 	bus_space_write_4(iot, ioh, GR2_FIFO_COLOR, color);
    251  1.2  sekiya }
    252  1.2  sekiya 
    253  1.1  sekiya /* Helper functions */
    254  1.1  sekiya static void
    255  1.1  sekiya grtwo_fill_rectangle(struct grtwo_devconfig * dc, int x1, int y1, int x2,
    256  1.1  sekiya 		     int y2, u_int8_t color)
    257  1.1  sekiya {
    258  1.2  sekiya 	int remaining;
    259  1.2  sekiya 	int from_y;
    260  1.2  sekiya 	int to_y;
    261  1.2  sekiya 
    262  1.2  sekiya 	/* gr2 sees coordinate 0,0 as the lower left corner, and 1279,1023
    263  1.2  sekiya 	   as the upper right.  To keep things consistent, we shall flip the
    264  1.2  sekiya 	   y axis. */
    265  1.2  sekiya 
    266  1.2  sekiya 	/* There appears to be a limit to the number of vertical lines that we
    267  1.2  sekiya 	   can run through the the graphics engine at one go.  This probably has
    268  1.2  sekiya 	   something to do with vertical refresh.  Single-row fills are okay,
    269  1.2  sekiya 	   multiple-row screw up the board in exciting ways.  The copy_rectangle
    270  1.2  sekiya 	   workaround doesn't work for fills. */
    271  1.2  sekiya 
    272  1.2  sekiya 	/* Coordinates, not length.  Remember that! */
    273  1.2  sekiya 
    274  1.2  sekiya 	to_y = min(dc->yres - 1 - y1, dc->yres - 1 - y2);
    275  1.2  sekiya 	from_y = max(dc->yres - 1 - y1, dc->yres - 1 - y2);
    276  1.2  sekiya 
    277  1.2  sekiya 	remaining = to_y - from_y;
    278  1.1  sekiya 
    279  1.1  sekiya 	grtwo_wait_gfifo(dc);
    280  1.2  sekiya 	grtwo_set_color(dc->iot, dc->ioh, color);
    281  1.2  sekiya 
    282  1.2  sekiya 	while (remaining) {
    283  1.2  sekiya 		if (remaining <= 32)
    284  1.2  sekiya 		{
    285  1.2  sekiya 			delay(10000);
    286  1.2  sekiya 			grtwo_wait_gfifo(dc);
    287  1.2  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_RECTI2D, x1);
    288  1.2  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, from_y);
    289  1.2  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, x2);
    290  1.2  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, from_y + remaining);
    291  1.2  sekiya 			break;
    292  1.2  sekiya 		} else {
    293  1.2  sekiya 			delay(100000);
    294  1.2  sekiya 			grtwo_wait_gfifo(dc);
    295  1.2  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_RECTI2D, x1);
    296  1.2  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, from_y);
    297  1.2  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, x2);
    298  1.2  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, from_y + remaining);
    299  1.2  sekiya 			from_y += 32;
    300  1.2  sekiya 			remaining -=32;
    301  1.2  sekiya 		}
    302  1.2  sekiya 	}
    303  1.1  sekiya }
    304  1.1  sekiya 
    305  1.1  sekiya static void
    306  1.1  sekiya grtwo_copy_rectangle(struct grtwo_devconfig * dc, int x1, int y1, int x2,
    307  1.2  sekiya 		     int y2, int width, int height)
    308  1.1  sekiya {
    309  1.2  sekiya 	int             length = (width + 3) >> 2;
    310  1.1  sekiya 	int             lines = 4864 / length;
    311  1.1  sekiya 	int             from_y;
    312  1.1  sekiya 	int             to_y;
    313  1.2  sekiya 	int		temp_height;
    314  1.1  sekiya 
    315  1.2  sekiya 	if ((y2 <= y1) || (height < lines)) {
    316  1.1  sekiya 		grtwo_wait_gfifo(dc);
    317  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_RECTCOPY, length);
    318  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, lines);
    319  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, x1);
    320  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, y1);
    321  1.2  sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, width);
    322  1.2  sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, height);
    323  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, x2);
    324  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, y2);
    325  1.1  sekiya 	} else {
    326  1.2  sekiya 		from_y = y1 + height - lines;
    327  1.2  sekiya 		to_y = y2 + height - lines;
    328  1.2  sekiya 		temp_height = MIN(height, lines);
    329  1.1  sekiya 
    330  1.2  sekiya 		while (temp_height) {
    331  1.1  sekiya 			grtwo_wait_gfifo(dc);
    332  1.1  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_RECTCOPY, length);
    333  1.1  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, lines);
    334  1.1  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, x1);
    335  1.1  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, from_y);
    336  1.2  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, width);
    337  1.2  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, temp_height);
    338  1.1  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, x2);
    339  1.1  sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, to_y);
    340  1.2  sekiya 			height -= temp_height;
    341  1.2  sekiya 			height = MIN(height, lines);
    342  1.2  sekiya 			from_y -= temp_height;
    343  1.2  sekiya 			to_y -= temp_height;
    344  1.1  sekiya 		}
    345  1.1  sekiya 	}
    346  1.1  sekiya }
    347  1.1  sekiya 
    348  1.1  sekiya static void
    349  1.1  sekiya grtwo_cmap_setrgb(struct grtwo_devconfig * dc, int index, u_int8_t r, u_int8_t g, u_int8_t b)
    350  1.1  sekiya {
    351  1.1  sekiya 	grtwo_wait_gfifo(dc);
    352  1.2  sekiya 	bus_space_write_1(dc->iot, dc->ioh, XMAPALL_ADDRHI,
    353  1.2  sekiya 			  ((index & 0x1f00) >> 8) );
    354  1.2  sekiya 	bus_space_write_1(dc->iot, dc->ioh, XMAPALL_ADDRLO,
    355  1.1  sekiya 			  (index & 0xff));
    356  1.2  sekiya 	bus_space_write_1(dc->iot, dc->ioh, XMAPALL_CLUT, r);
    357  1.2  sekiya 	bus_space_write_1(dc->iot, dc->ioh, XMAPALL_CLUT, g);
    358  1.2  sekiya 	bus_space_write_1(dc->iot, dc->ioh, XMAPALL_CLUT, b);
    359  1.1  sekiya }
    360  1.1  sekiya 
    361  1.1  sekiya static void
    362  1.1  sekiya grtwo_setup_hw(struct grtwo_devconfig * dc)
    363  1.1  sekiya {
    364  1.1  sekiya 	int             i = 0;
    365  1.1  sekiya 
    366  1.1  sekiya 	/* Get various revisions */
    367  1.1  sekiya 	dc->boardrev = (~(bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD0))) & GR2_REVISION_RD0_VERSION_MASK;
    368  1.1  sekiya 
    369  1.1  sekiya 	/*
    370  1.1  sekiya 	 * boards prior to rev 4 have a pretty whacky config scheme.
    371  1.1  sekiya          * what is doubly weird is that i have a rev 2 board, but the rev 4
    372  1.1  sekiya 	 * probe routines work just fine.
    373  1.1  sekiya 	 * we'll trust SGI, though, and separate things a bit.  it's only
    374  1.1  sekiya 	 * critical for the display depth calculation.
    375  1.1  sekiya 	 */
    376  1.1  sekiya 
    377  1.1  sekiya 	if (dc->boardrev < 4) {
    378  1.1  sekiya 		dc->backendrev = ~(bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD2) & GR2_REVISION_RD2_BACKEND_REV) >> 2;
    379  1.1  sekiya 		if (dc->backendrev == 0)
    380  1.1  sekiya 			return;
    381  1.1  sekiya 		dc->zbuffer = !(bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD1) & GR2_REVISION_RD1_ZBUFFER);
    382  1.1  sekiya 		if ( (bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD3) & GR2_REVISION_RD3_VMA) != 3)
    383  1.1  sekiya 		  i++;
    384  1.1  sekiya 		if ( (bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD3) & GR2_REVISION_RD3_VMB) != 0x0c)
    385  1.1  sekiya 		  i++;
    386  1.1  sekiya 		if ( (bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD3) & GR2_REVISION_RD3_VMC) != 0x30)
    387  1.1  sekiya 		  i++;
    388  1.1  sekiya 		dc->depth = 8 * i;
    389  1.1  sekiya 		dc->monitor =
    390  1.1  sekiya 			((bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD2) & 0x03) << 1) |
    391  1.1  sekiya 			(bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD1) & 0x01);
    392  1.1  sekiya 	} else {
    393  1.1  sekiya 		dc->backendrev = ~(bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD1)) & 0x03;
    394  1.1  sekiya 		if (dc->backendrev == 0)
    395  1.1  sekiya 			return;
    396  1.1  sekiya 		dc->zbuffer = bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD1) & GR2_REVISION4_RD1_ZBUFFER;
    397  1.1  sekiya 		dc->depth = ((bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD1) & GR2_REVISION4_RD1_24BPP) >> 4) ? 24 : 8;
    398  1.1  sekiya 		dc->monitor = (bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD0) & GR2_REVISION4_RD0_MONITOR_MASK) >> 4;
    399  1.1  sekiya 	}
    400  1.1  sekiya 
    401  1.1  sekiya 	dc->hq2rev = (bus_space_read_4(dc->iot, dc->ioh, HQ2_VERSION) & HQ2_VERSION_MASK) >> HQ2_VERSION_SHIFT;
    402  1.1  sekiya 	dc->ge7rev = (bus_space_read_4(dc->iot, dc->ioh, GE7_REVISION) & GE7_REVISION_MASK) >> 5;
    403  1.1  sekiya 	/* dc->vc1rev = vc1_read_ireg(dc, 5) & 0x07; */
    404  1.1  sekiya 
    405  1.1  sekiya 	/* gr2 supports 1280x1024 only */
    406  1.1  sekiya 	dc->xres = 1280;
    407  1.1  sekiya 	dc->yres = 1024;
    408  1.1  sekiya 
    409  1.1  sekiya #if 0
    410  1.1  sekiya 	/* Setup cursor glyph */
    411  1.1  sekiya 
    412  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_ADDRHI,
    413  1.1  sekiya 		(VC1_SRAM_CURSOR0_BASE >> 8) & 0xff);
    414  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_ADDRLO,
    415  1.1  sekiya 		VC1_SRAM_CURSOR0_BASE & 0xff);
    416  1.1  sekiya 	for (i = 0; i < 128; i++)
    417  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_SRAM, grtwo_cursor_data[i]);
    418  1.1  sekiya 
    419  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_ADDRHI,
    420  1.1  sekiya 		(VC1_CURSOR_EP >> 8) & 0xff);
    421  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_ADDRLO,
    422  1.1  sekiya 		VC1_CURSOR_EP & 0xff);
    423  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_COMMAND, VC1_SRAM_CURSOR0_BASE);
    424  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_COMMAND, 0);
    425  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_COMMAND, 0);
    426  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_COMMAND, 0);
    427  1.1  sekiya 
    428  1.1  sekiya 	/* Turn on cursor function, display, DID */
    429  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_SYSCTL,
    430  1.1  sekiya 		VC1_SYSCTL_VC1 | VC1_SYSCTL_DID |
    431  1.1  sekiya 		VC1_SYSCTL_CURSOR | VC1_SYSCTL_CURSOR_DISPLAY);
    432  1.1  sekiya #endif
    433  1.1  sekiya 
    434  1.1  sekiya 	/* Setup CMAP */
    435  1.1  sekiya 	for (i = 0; i < 8; i++)
    436  1.1  sekiya 		grtwo_cmap_setrgb(dc, i, grtwo_defcmap[i * 3],
    437  1.1  sekiya 			grtwo_defcmap[i * 3 + 1], grtwo_defcmap[i * 3 + 2]);
    438  1.1  sekiya }
    439  1.1  sekiya 
    440  1.1  sekiya /* Attach routines */
    441  1.1  sekiya static int
    442  1.1  sekiya grtwo_match(struct device * parent, struct cfdata * self, void *aux)
    443  1.1  sekiya {
    444  1.1  sekiya 	struct gio_attach_args *ga = aux;
    445  1.1  sekiya 
    446  1.8  rumble 	if (ga->ga_addr != 0x1f000000 && ga->ga_addr != 0x1f400000 &&
    447  1.8  rumble 	    ga->ga_addr != 0x1f600000)
    448  1.8  rumble 		return (0);
    449  1.8  rumble 
    450  1.1  sekiya 	/*
    451  1.1  sekiya 	 * grtwo doesn't have anything that even vaguely resembles a product
    452  1.1  sekiya 	 * ID.  Instead, we determine presence by looking at the HQ2 "mystery"
    453  1.1  sekiya 	 * register, which contains a magic number.
    454  1.1  sekiya 	 */
    455  1.1  sekiya 	if ( badaddr((void *) (ga->ga_ioh + HQ2_MYSTERY), sizeof(u_int32_t)) )
    456  1.1  sekiya 		return 0;
    457  1.1  sekiya 
    458  1.1  sekiya 	if ( (bus_space_read_4(ga->ga_iot, ga->ga_ioh, HQ2_MYSTERY)) != 0xdeadbeef)
    459  1.1  sekiya 		return 0;
    460  1.1  sekiya 
    461  1.1  sekiya 	return 1;
    462  1.1  sekiya }
    463  1.1  sekiya 
    464  1.1  sekiya static void
    465  1.1  sekiya grtwo_attach_common(struct grtwo_devconfig * dc, struct gio_attach_args * ga)
    466  1.1  sekiya {
    467  1.1  sekiya 	dc->dc_addr = ga->ga_addr;
    468  1.1  sekiya 
    469  1.1  sekiya 	dc->iot = ga->ga_iot;
    470  1.1  sekiya 	dc->ioh = ga->ga_ioh;
    471  1.2  sekiya 	int i = 0;
    472  1.1  sekiya 
    473  1.1  sekiya 	wsfont_init();
    474  1.1  sekiya 
    475  1.1  sekiya 	dc->dc_font = wsfont_find(NULL, 8, 16, 0, WSDISPLAY_FONTORDER_L2R,
    476  1.1  sekiya 				  WSDISPLAY_FONTORDER_L2R);
    477  1.1  sekiya 
    478  1.1  sekiya 	if (dc->dc_font < 0)
    479  1.1  sekiya 		panic("grtwo_attach_common: no suitable fonts");
    480  1.1  sekiya 
    481  1.1  sekiya 	if (wsfont_lock(dc->dc_font, &dc->dc_fontdata))
    482  1.1  sekiya 		panic("grtwo_attach_common: unable to lock font data");
    483  1.1  sekiya 
    484  1.1  sekiya 	grtwo_setup_hw(dc);
    485  1.1  sekiya 
    486  1.2  sekiya 	/* Large fills are broken.  For now, clear the screen line-by-line. */
    487  1.2  sekiya 	for (i = 0; i < 64; i++)
    488  1.2  sekiya 		grtwo_eraserows(dc, i, 1, 0);
    489  1.2  sekiya 
    490  1.2  sekiya 	/* If large fills worked, we'd do this instead:
    491  1.2  sekiya 	grtwo_fill_rectangle(dc, 0, 0, dc->xres - 1, dc->yres - 1, 0);
    492  1.2  sekiya 	*/
    493  1.1  sekiya }
    494  1.1  sekiya 
    495  1.1  sekiya static void
    496  1.1  sekiya grtwo_attach(struct device * parent, struct device * self, void *aux)
    497  1.1  sekiya {
    498  1.1  sekiya 	struct gio_attach_args *ga = aux;
    499  1.1  sekiya 	struct grtwo_softc *sc = (void *) self;
    500  1.1  sekiya 	struct wsemuldisplaydev_attach_args wa;
    501  1.1  sekiya 
    502  1.1  sekiya 	if (grtwo_is_console && ga->ga_addr == grtwo_console_dc.dc_addr) {
    503  1.1  sekiya 		wa.console = 1;
    504  1.1  sekiya 		sc->sc_dc = &grtwo_console_dc;
    505  1.1  sekiya 	} else {
    506  1.1  sekiya 		wa.console = 0;
    507  1.1  sekiya 		sc->sc_dc = malloc(sizeof(struct grtwo_devconfig),
    508  1.1  sekiya 				   M_DEVBUF, M_WAITOK | M_ZERO);
    509  1.1  sekiya 		if (sc->sc_dc == NULL)
    510  1.1  sekiya 			panic("grtwo_attach: out of memory");
    511  1.1  sekiya 
    512  1.1  sekiya 		grtwo_attach_common(sc->sc_dc, ga);
    513  1.1  sekiya 	}
    514  1.1  sekiya 
    515  1.1  sekiya 	aprint_naive(": Display adapter\n");
    516  1.1  sekiya 
    517  1.5  sekiya 	aprint_normal(": GR2 (board rev %x, monitor %d, depth %d)\n",
    518  1.1  sekiya 	      sc->sc_dc->boardrev, sc->sc_dc->monitor, sc->sc_dc->depth);
    519  1.1  sekiya 
    520  1.1  sekiya 	wa.scrdata = &grtwo_screenlist;
    521  1.1  sekiya 	wa.accessops = &grtwo_accessops;
    522  1.1  sekiya 	wa.accesscookie = sc->sc_dc;
    523  1.1  sekiya 
    524  1.2  sekiya         if ((cpu_intr_establish(0, IPL_TTY, grtwo_intr0, sc)) == NULL)
    525  1.2  sekiya                 printf(": unable to establish interrupt!\n");
    526  1.2  sekiya 
    527  1.2  sekiya         if ((cpu_intr_establish(6, IPL_TTY, grtwo_intr6, sc)) == NULL)
    528  1.2  sekiya                 printf(": unable to establish interrupt!\n");
    529  1.2  sekiya 
    530  1.1  sekiya 	config_found(&sc->sc_dev, &wa, wsemuldisplaydevprint);
    531  1.1  sekiya }
    532  1.1  sekiya 
    533  1.1  sekiya int
    534  1.1  sekiya grtwo_cnattach(struct gio_attach_args * ga)
    535  1.1  sekiya {
    536  1.1  sekiya 	long            defattr = GR2_ATTR_ENCODE(WSCOL_WHITE, WSCOL_BLACK);
    537  1.1  sekiya 
    538  1.1  sekiya 	if (!grtwo_match(NULL, NULL, ga)) {
    539  1.1  sekiya 		return ENXIO;
    540  1.1  sekiya 	}
    541  1.1  sekiya 
    542  1.1  sekiya 	grtwo_attach_common(&grtwo_console_dc, ga);
    543  1.4  sekiya 	wsdisplay_cnattach(&grtwo_screen, &grtwo_console_dc, 0, 0, defattr);
    544  1.1  sekiya 
    545  1.1  sekiya 	grtwo_is_console = 1;
    546  1.1  sekiya 
    547  1.1  sekiya 	return 0;
    548  1.1  sekiya }
    549  1.1  sekiya 
    550  1.1  sekiya /* wsdisplay textops */
    551  1.1  sekiya static void
    552  1.1  sekiya grtwo_cursor(void *c, int on, int row, int col)
    553  1.1  sekiya {
    554  1.1  sekiya 	struct grtwo_devconfig *dc = (void *) c;
    555  1.1  sekiya 	u_int32_t control;
    556  1.1  sekiya 	control = bus_space_read_4(dc->iot, dc->ioh, VC1_SYSCTL);
    557  1.1  sekiya 
    558  1.1  sekiya 	if (!on) {
    559  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_SYSCTL,
    560  1.1  sekiya 			control & ~VC1_SYSCTL_CURSOR_DISPLAY);
    561  1.1  sekiya 	} else {
    562  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_ADDRHI, (VC1_CURSOR_XL & 0xff00) >> 8
    563  1.1  sekiya 			);
    564  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_ADDRLO, VC1_CURSOR_XL & 0xff);
    565  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_COMMAND,
    566  1.1  sekiya 				  col * dc->dc_fontdata->fontwidth);
    567  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_COMMAND,
    568  1.1  sekiya 				  row * dc->dc_fontdata->fontheight);
    569  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_SYSCTL,
    570  1.1  sekiya 			control | VC1_SYSCTL_CURSOR_DISPLAY);
    571  1.1  sekiya 	}
    572  1.1  sekiya }
    573  1.1  sekiya 
    574  1.1  sekiya static int
    575  1.1  sekiya grtwo_mapchar(void *c, int ch, unsigned int *cp)
    576  1.1  sekiya {
    577  1.1  sekiya 	struct grtwo_devconfig *dc = (void *) c;
    578  1.1  sekiya 
    579  1.1  sekiya 	if (dc->dc_fontdata->encoding != WSDISPLAY_FONTENC_ISO) {
    580  1.1  sekiya 		ch = wsfont_map_unichar(dc->dc_fontdata, ch);
    581  1.1  sekiya 
    582  1.1  sekiya 		if (ch < 0)
    583  1.1  sekiya 			goto fail;
    584  1.1  sekiya 	}
    585  1.1  sekiya 	if (ch < dc->dc_fontdata->firstchar ||
    586  1.1  sekiya 	    ch >= dc->dc_fontdata->firstchar + dc->dc_fontdata->numchars)
    587  1.1  sekiya 		goto fail;
    588  1.1  sekiya 
    589  1.1  sekiya 	*cp = ch;
    590  1.1  sekiya 	return 5;
    591  1.1  sekiya 
    592  1.1  sekiya fail:
    593  1.1  sekiya 	*cp = ' ';
    594  1.1  sekiya 	return 0;
    595  1.1  sekiya }
    596  1.1  sekiya 
    597  1.1  sekiya static void
    598  1.1  sekiya grtwo_putchar(void *c, int row, int col, u_int ch, long attr)
    599  1.1  sekiya {
    600  1.1  sekiya 	struct grtwo_devconfig *dc = (void *) c;
    601  1.1  sekiya 	struct wsdisplay_font *font = dc->dc_fontdata;
    602  1.2  sekiya 	u_int8_t        *bitmap = (u_int8_t *) font->data + (ch - font->firstchar + 1) * font->fontheight * font->stride;
    603  1.1  sekiya 	u_int32_t        pattern;
    604  1.1  sekiya 	int             i;
    605  1.1  sekiya 	int             x = col * font->fontwidth;
    606  1.1  sekiya 	int             y = dc->yres - ( (row + 1) * font->fontheight);
    607  1.1  sekiya 
    608  1.1  sekiya 	/* Set the drawing color */
    609  1.1  sekiya 	grtwo_wait_gfifo(dc);
    610  1.2  sekiya 	grtwo_set_color(dc->iot, dc->ioh, (((attr) >> 8) & 0xff));
    611  1.2  sekiya 	grtwo_wait_gfifo(dc);
    612  1.1  sekiya 
    613  1.1  sekiya 	/* Set drawing coordinates */
    614  1.1  sekiya 	grtwo_wait_gfifo(dc);
    615  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_CMOV2I, x);
    616  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, y);
    617  1.1  sekiya 
    618  1.2  sekiya 	/* This works for font sizes < 18 */
    619  1.1  sekiya 	grtwo_wait_gfifo(dc);
    620  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DRAWCHAR, font->fontwidth);
    621  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, font->fontheight);
    622  1.2  sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, 2);
    623  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, 0); /* x offset */
    624  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, 0); /* y offset */
    625  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, 0);
    626  1.1  sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, 0);
    627  1.1  sekiya 
    628  1.1  sekiya 	for (i = 0; i < font->fontheight; i++) {
    629  1.1  sekiya 		/* It appears that writes have to be 16 bits.  An "I tell you
    630  1.1  sekiya 		   two times" sort of thing?  Thanks, SGI */
    631  1.1  sekiya 		pattern = *bitmap | (*bitmap << 8);
    632  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, pattern);
    633  1.2  sekiya 		bitmap -= font->stride;
    634  1.1  sekiya 	}
    635  1.1  sekiya 
    636  1.1  sekiya 	/* pad up to 18 */
    637  1.1  sekiya 	for (i = font->fontheight; i < 18; i++)
    638  1.1  sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, 0x0000);
    639  1.1  sekiya }
    640  1.1  sekiya 
    641  1.1  sekiya static void
    642  1.1  sekiya grtwo_copycols(void *c, int row, int srccol, int dstcol, int ncols)
    643  1.1  sekiya {
    644  1.2  sekiya #if 1
    645  1.2  sekiya 	printf("grtwo_copycols: %i %i %i %i\n", row, srccol, dstcol, ncols);
    646  1.2  sekiya #else
    647  1.1  sekiya 	struct grtwo_devconfig *dc = (void *) c;
    648  1.1  sekiya 	struct wsdisplay_font *font = dc->dc_fontdata;
    649  1.1  sekiya 	grtwo_copy_rectangle(dc,
    650  1.1  sekiya 			     srccol * font->fontwidth,	/* x1 */
    651  1.2  sekiya 			     0,	/* y1 */
    652  1.2  sekiya 			     dstcol * font->fontwidth,	/* x2 */
    653  1.2  sekiya 			     0,	/* y2 */
    654  1.2  sekiya 			     ncols * font->fontwidth,	/* dx */
    655  1.2  sekiya 			     dc->yres );	/* dy */
    656  1.2  sekiya #endif
    657  1.1  sekiya }
    658  1.1  sekiya 
    659  1.1  sekiya static void
    660  1.1  sekiya grtwo_erasecols(void *c, int row, int startcol, int ncols, long attr)
    661  1.1  sekiya {
    662  1.1  sekiya 	struct grtwo_devconfig *dc = (void *) c;
    663  1.1  sekiya 	struct wsdisplay_font *font = dc->dc_fontdata;
    664  1.1  sekiya 
    665  1.1  sekiya 	grtwo_fill_rectangle(dc,
    666  1.1  sekiya 			     startcol * font->fontwidth,	/* x1 */
    667  1.2  sekiya 			     0,	/* y1 */
    668  1.2  sekiya 			     (startcol * font->fontwidth) + ncols * font->fontwidth,	/* x2 */
    669  1.2  sekiya 			     dc->yres,	/* y2 */
    670  1.1  sekiya 			     GR2_ATTR_BG(attr));
    671  1.1  sekiya }
    672  1.1  sekiya 
    673  1.1  sekiya static void
    674  1.1  sekiya grtwo_copyrows(void *c, int srcrow, int dstrow, int nrows)
    675  1.1  sekiya {
    676  1.1  sekiya 	struct grtwo_devconfig *dc = (void *) c;
    677  1.1  sekiya 	struct wsdisplay_font *font = dc->dc_fontdata;
    678  1.1  sekiya 
    679  1.1  sekiya 	grtwo_copy_rectangle(dc,
    680  1.1  sekiya 			     0,	/* x1 */
    681  1.1  sekiya 			     srcrow * font->fontheight,	/* y1 */
    682  1.2  sekiya 			     0, /* x2 */
    683  1.2  sekiya 			     dstrow * font->fontheight,	/* y2 */
    684  1.2  sekiya 			     dc->xres,	/* dx */
    685  1.2  sekiya 			     nrows * font->fontheight);
    686  1.1  sekiya }
    687  1.1  sekiya 
    688  1.1  sekiya static void
    689  1.1  sekiya grtwo_eraserows(void *c, int startrow, int nrows, long attr)
    690  1.1  sekiya {
    691  1.1  sekiya 	struct grtwo_devconfig *dc = (void *) c;
    692  1.1  sekiya 	struct wsdisplay_font *font = dc->dc_fontdata;
    693  1.1  sekiya 	grtwo_fill_rectangle(dc,
    694  1.1  sekiya 			     0,	/* x1 */
    695  1.1  sekiya 			     startrow * font->fontheight,	/* y1 */
    696  1.1  sekiya 			     dc->xres,	/* x2 */
    697  1.2  sekiya 			     (startrow * font->fontheight) + nrows * font->fontheight,	/* y2 */
    698  1.1  sekiya 			     GR2_ATTR_BG(attr));
    699  1.1  sekiya }
    700  1.1  sekiya 
    701  1.1  sekiya static int
    702  1.1  sekiya grtwo_allocattr(void *c, int fg, int bg, int flags, long *attr)
    703  1.1  sekiya {
    704  1.1  sekiya 	if (flags & WSATTR_BLINK)
    705  1.1  sekiya 		return EINVAL;
    706  1.1  sekiya 
    707  1.1  sekiya 	if ((flags & WSATTR_WSCOLORS) == 0) {
    708  1.1  sekiya 		fg = WSCOL_WHITE;
    709  1.1  sekiya 		bg = WSCOL_BLACK;
    710  1.1  sekiya 	}
    711  1.1  sekiya 	if (flags & WSATTR_HILIT)
    712  1.1  sekiya 		fg += 8;
    713  1.1  sekiya 
    714  1.1  sekiya 	if (flags & WSATTR_REVERSE) {
    715  1.1  sekiya 		int             tmp = fg;
    716  1.1  sekiya 		fg = bg;
    717  1.1  sekiya 		bg = tmp;
    718  1.1  sekiya 	}
    719  1.1  sekiya 	*attr = GR2_ATTR_ENCODE(fg, bg);
    720  1.1  sekiya 
    721  1.1  sekiya 	return 0;
    722  1.1  sekiya }
    723  1.1  sekiya 
    724  1.1  sekiya /* wsdisplay accessops */
    725  1.1  sekiya 
    726  1.1  sekiya static int
    727  1.7    jmmv grtwo_ioctl(void *c, void *vs, u_long cmd, caddr_t data, int flag,
    728  1.7    jmmv 	struct lwp *l)
    729  1.1  sekiya {
    730  1.1  sekiya 	struct grtwo_softc *sc = c;
    731  1.1  sekiya 
    732  1.1  sekiya #define FBINFO (*(struct wsdisplay_fbinfo*)data)
    733  1.1  sekiya 
    734  1.1  sekiya 	switch (cmd) {
    735  1.1  sekiya 	case WSDISPLAYIO_GINFO:
    736  1.1  sekiya 		FBINFO.width = sc->sc_dc->xres;
    737  1.1  sekiya 		FBINFO.height = sc->sc_dc->yres;
    738  1.1  sekiya 		FBINFO.depth = sc->sc_dc->depth;
    739  1.1  sekiya 		FBINFO.cmsize = 1 << FBINFO.depth;
    740  1.1  sekiya 		return 0;
    741  1.1  sekiya 	case WSDISPLAYIO_GTYPE:
    742  1.1  sekiya 		*(u_int *) data = WSDISPLAY_TYPE_GR2;
    743  1.1  sekiya 		return 0;
    744  1.1  sekiya 	}
    745  1.1  sekiya 	return EPASSTHROUGH;
    746  1.1  sekiya }
    747  1.1  sekiya 
    748  1.1  sekiya static          paddr_t
    749  1.7    jmmv grtwo_mmap(void *c, void *vs, off_t offset, int prot)
    750  1.1  sekiya {
    751  1.1  sekiya 	struct grtwo_devconfig *dc = c;
    752  1.1  sekiya 
    753  1.1  sekiya 	if (offset >= 0xfffff)
    754  1.1  sekiya 		return -1;
    755  1.1  sekiya 
    756  1.1  sekiya 	return mips_btop(dc->dc_addr + offset);
    757  1.1  sekiya }
    758  1.1  sekiya 
    759  1.1  sekiya static int
    760  1.1  sekiya grtwo_alloc_screen(void *c, const struct wsscreen_descr * type, void **cookiep,
    761  1.1  sekiya 		   int *cursxp, int *cursyp, long *attrp)
    762  1.1  sekiya {
    763  1.1  sekiya 	/*
    764  1.1  sekiya 	 * This won't get called for console screen and we don't support
    765  1.1  sekiya 	 * virtual screens
    766  1.1  sekiya 	 */
    767  1.1  sekiya 
    768  1.1  sekiya 	return ENOMEM;
    769  1.1  sekiya }
    770  1.1  sekiya 
    771  1.1  sekiya static void
    772  1.1  sekiya grtwo_free_screen(void *c, void *cookie)
    773  1.1  sekiya {
    774  1.1  sekiya 	panic("grtwo_free_screen");
    775  1.1  sekiya }
    776  1.1  sekiya static int
    777  1.1  sekiya grtwo_show_screen(void *c, void *cookie, int waitok,
    778  1.1  sekiya 		  void (*cb) (void *, int, int), void *cbarg)
    779  1.1  sekiya {
    780  1.1  sekiya 	return 0;
    781  1.1  sekiya }
    782  1.2  sekiya 
    783  1.2  sekiya static int
    784  1.2  sekiya grtwo_intr0(void *arg)
    785  1.2  sekiya {
    786  1.2  sekiya 	/* struct grtwo_devconfig *dc = arg; */
    787  1.2  sekiya 	return 1;
    788  1.2  sekiya }
    789  1.2  sekiya 
    790  1.2  sekiya 
    791  1.2  sekiya static int
    792  1.2  sekiya grtwo_intr6(void *arg)
    793  1.2  sekiya {
    794  1.2  sekiya 	/* struct grtwo_devconfig *dc = arg; */
    795  1.2  sekiya 	return 1;
    796  1.2  sekiya }
    797  1.2  sekiya 
    798