Home | History | Annotate | Line # | Download | only in gio
grtwo.c revision 1.15
      1  1.15  riastrad /* $NetBSD: grtwo.c,v 1.15 2018/09/03 16:29:27 riastradh 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.15  riastrad __KERNEL_RCSID(0, "$NetBSD: grtwo.c,v 1.15 2018/09/03 16:29:27 riastradh 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.9    rumble #include <machine/sysconf.h>
     46   1.9    rumble 
     47   1.1    sekiya #include <dev/wscons/wsconsio.h>
     48   1.1    sekiya #include <dev/wscons/wsdisplayvar.h>
     49   1.1    sekiya #include <dev/wsfont/wsfont.h>
     50   1.1    sekiya 
     51   1.1    sekiya #include <sgimips/gio/giovar.h>
     52   1.1    sekiya #include <sgimips/gio/grtwovar.h>
     53   1.1    sekiya #include <sgimips/gio/grtworeg.h>
     54   1.1    sekiya 
     55   1.1    sekiya #include <sgimips/dev/int2var.h>
     56   1.1    sekiya 
     57   1.1    sekiya struct grtwo_softc {
     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.13       chs static int      grtwo_match(device_t, cfdata_t, void *);
     86  1.13       chs static void     grtwo_attach(device_t, device_t, void *);
     87   1.1    sekiya 
     88  1.13       chs CFATTACH_DECL_NEW(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.10  christos static int      grtwo_ioctl(void *, void *, u_long, void *, 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.14       mrg #if 0
    160   1.1    sekiya static const u_int16_t grtwo_cursor_data[128] = {
    161   1.1    sekiya 	/* Bit 0 */
    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 	0xff00, 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 	0x0000, 0x0000,
    194   1.1    sekiya 
    195   1.1    sekiya 	/* Bit 1 */
    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 	0x0000, 0x0000,
    228   1.1    sekiya };
    229  1.14       mrg #endif
    230   1.1    sekiya 
    231   1.1    sekiya static const u_int8_t grtwo_defcmap[8 * 3] = {
    232   1.1    sekiya 	/* Normal colors */
    233   1.1    sekiya 	0x00, 0x00, 0x00,	/* black */
    234   1.1    sekiya 	0x7f, 0x00, 0x00,	/* red */
    235   1.1    sekiya 	0x00, 0x7f, 0x00,	/* green */
    236   1.1    sekiya 	0x7f, 0x7f, 0x00,	/* brown */
    237   1.1    sekiya 	0x00, 0x00, 0x7f,	/* blue */
    238   1.1    sekiya 	0x7f, 0x00, 0x7f,	/* magenta */
    239   1.1    sekiya 	0x00, 0x7f, 0x7f,	/* cyan */
    240   1.1    sekiya 	0xc7, 0xc7, 0xc7,	/* white - XXX too dim? */
    241   1.1    sekiya };
    242   1.1    sekiya 
    243   1.1    sekiya static void
    244   1.1    sekiya grtwo_wait_gfifo(struct grtwo_devconfig * dc)
    245   1.1    sekiya {
    246   1.1    sekiya 	int2_wait_fifo(1);
    247   1.1    sekiya }
    248   1.1    sekiya 
    249   1.2    sekiya static inline void
    250   1.2    sekiya grtwo_set_color(bus_space_tag_t iot, bus_space_handle_t ioh, int color)
    251   1.2    sekiya {
    252   1.2    sekiya 	bus_space_write_4(iot, ioh, GR2_FIFO_COLOR, color);
    253   1.2    sekiya }
    254   1.2    sekiya 
    255   1.1    sekiya /* Helper functions */
    256   1.1    sekiya static void
    257   1.1    sekiya grtwo_fill_rectangle(struct grtwo_devconfig * dc, int x1, int y1, int x2,
    258   1.1    sekiya 		     int y2, u_int8_t color)
    259   1.1    sekiya {
    260   1.2    sekiya 	int remaining;
    261   1.2    sekiya 	int from_y;
    262   1.2    sekiya 	int to_y;
    263   1.2    sekiya 
    264   1.2    sekiya 	/* gr2 sees coordinate 0,0 as the lower left corner, and 1279,1023
    265   1.2    sekiya 	   as the upper right.  To keep things consistent, we shall flip the
    266   1.2    sekiya 	   y axis. */
    267   1.2    sekiya 
    268   1.2    sekiya 	/* There appears to be a limit to the number of vertical lines that we
    269  1.11   mbalmer 	   can run through the graphics engine at one go.  This probably has
    270   1.2    sekiya 	   something to do with vertical refresh.  Single-row fills are okay,
    271   1.2    sekiya 	   multiple-row screw up the board in exciting ways.  The copy_rectangle
    272   1.2    sekiya 	   workaround doesn't work for fills. */
    273   1.2    sekiya 
    274   1.2    sekiya 	/* Coordinates, not length.  Remember that! */
    275   1.2    sekiya 
    276  1.15  riastrad 	to_y = uimin(dc->yres - 1 - y1, dc->yres - 1 - y2);
    277  1.15  riastrad 	from_y = uimax(dc->yres - 1 - y1, dc->yres - 1 - y2);
    278   1.2    sekiya 
    279   1.2    sekiya 	remaining = to_y - from_y;
    280   1.1    sekiya 
    281   1.1    sekiya 	grtwo_wait_gfifo(dc);
    282   1.2    sekiya 	grtwo_set_color(dc->iot, dc->ioh, color);
    283   1.2    sekiya 
    284   1.2    sekiya 	while (remaining) {
    285   1.2    sekiya 		if (remaining <= 32)
    286   1.2    sekiya 		{
    287   1.2    sekiya 			delay(10000);
    288   1.2    sekiya 			grtwo_wait_gfifo(dc);
    289   1.2    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_RECTI2D, x1);
    290   1.2    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, from_y);
    291   1.2    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, x2);
    292   1.2    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, from_y + remaining);
    293   1.2    sekiya 			break;
    294   1.2    sekiya 		} else {
    295   1.2    sekiya 			delay(100000);
    296   1.2    sekiya 			grtwo_wait_gfifo(dc);
    297   1.2    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_RECTI2D, x1);
    298   1.2    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, from_y);
    299   1.2    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, x2);
    300   1.2    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, from_y + remaining);
    301   1.2    sekiya 			from_y += 32;
    302   1.2    sekiya 			remaining -=32;
    303   1.2    sekiya 		}
    304   1.2    sekiya 	}
    305   1.1    sekiya }
    306   1.1    sekiya 
    307   1.1    sekiya static void
    308   1.1    sekiya grtwo_copy_rectangle(struct grtwo_devconfig * dc, int x1, int y1, int x2,
    309   1.2    sekiya 		     int y2, int width, int height)
    310   1.1    sekiya {
    311   1.2    sekiya 	int             length = (width + 3) >> 2;
    312   1.1    sekiya 	int             lines = 4864 / length;
    313   1.1    sekiya 	int             from_y;
    314   1.1    sekiya 	int             to_y;
    315   1.2    sekiya 	int		temp_height;
    316   1.1    sekiya 
    317   1.2    sekiya 	if ((y2 <= y1) || (height < lines)) {
    318   1.1    sekiya 		grtwo_wait_gfifo(dc);
    319   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_RECTCOPY, length);
    320   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, lines);
    321   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, x1);
    322   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, y1);
    323   1.2    sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, width);
    324   1.2    sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, height);
    325   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, x2);
    326   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, y2);
    327   1.1    sekiya 	} else {
    328   1.2    sekiya 		from_y = y1 + height - lines;
    329   1.2    sekiya 		to_y = y2 + height - lines;
    330   1.2    sekiya 		temp_height = MIN(height, lines);
    331   1.1    sekiya 
    332   1.2    sekiya 		while (temp_height) {
    333   1.1    sekiya 			grtwo_wait_gfifo(dc);
    334   1.1    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_RECTCOPY, length);
    335   1.1    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, lines);
    336   1.1    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, x1);
    337   1.1    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, from_y);
    338   1.2    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, width);
    339   1.2    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, temp_height);
    340   1.1    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, x2);
    341   1.1    sekiya 			bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, to_y);
    342   1.2    sekiya 			height -= temp_height;
    343   1.2    sekiya 			height = MIN(height, lines);
    344   1.2    sekiya 			from_y -= temp_height;
    345   1.2    sekiya 			to_y -= temp_height;
    346   1.1    sekiya 		}
    347   1.1    sekiya 	}
    348   1.1    sekiya }
    349   1.1    sekiya 
    350   1.1    sekiya static void
    351   1.1    sekiya grtwo_cmap_setrgb(struct grtwo_devconfig * dc, int index, u_int8_t r, u_int8_t g, u_int8_t b)
    352   1.1    sekiya {
    353   1.1    sekiya 	grtwo_wait_gfifo(dc);
    354   1.2    sekiya 	bus_space_write_1(dc->iot, dc->ioh, XMAPALL_ADDRHI,
    355   1.2    sekiya 			  ((index & 0x1f00) >> 8) );
    356   1.2    sekiya 	bus_space_write_1(dc->iot, dc->ioh, XMAPALL_ADDRLO,
    357   1.1    sekiya 			  (index & 0xff));
    358   1.2    sekiya 	bus_space_write_1(dc->iot, dc->ioh, XMAPALL_CLUT, r);
    359   1.2    sekiya 	bus_space_write_1(dc->iot, dc->ioh, XMAPALL_CLUT, g);
    360   1.2    sekiya 	bus_space_write_1(dc->iot, dc->ioh, XMAPALL_CLUT, b);
    361   1.1    sekiya }
    362   1.1    sekiya 
    363   1.1    sekiya static void
    364   1.1    sekiya grtwo_setup_hw(struct grtwo_devconfig * dc)
    365   1.1    sekiya {
    366   1.1    sekiya 	int             i = 0;
    367   1.1    sekiya 
    368   1.1    sekiya 	/* Get various revisions */
    369   1.1    sekiya 	dc->boardrev = (~(bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD0))) & GR2_REVISION_RD0_VERSION_MASK;
    370   1.1    sekiya 
    371   1.1    sekiya 	/*
    372   1.1    sekiya 	 * boards prior to rev 4 have a pretty whacky config scheme.
    373   1.1    sekiya          * what is doubly weird is that i have a rev 2 board, but the rev 4
    374   1.1    sekiya 	 * probe routines work just fine.
    375   1.1    sekiya 	 * we'll trust SGI, though, and separate things a bit.  it's only
    376   1.1    sekiya 	 * critical for the display depth calculation.
    377   1.1    sekiya 	 */
    378   1.1    sekiya 
    379   1.1    sekiya 	if (dc->boardrev < 4) {
    380   1.1    sekiya 		dc->backendrev = ~(bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD2) & GR2_REVISION_RD2_BACKEND_REV) >> 2;
    381   1.1    sekiya 		if (dc->backendrev == 0)
    382   1.1    sekiya 			return;
    383   1.1    sekiya 		dc->zbuffer = !(bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD1) & GR2_REVISION_RD1_ZBUFFER);
    384   1.1    sekiya 		if ( (bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD3) & GR2_REVISION_RD3_VMA) != 3)
    385   1.1    sekiya 		  i++;
    386   1.1    sekiya 		if ( (bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD3) & GR2_REVISION_RD3_VMB) != 0x0c)
    387   1.1    sekiya 		  i++;
    388   1.1    sekiya 		if ( (bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD3) & GR2_REVISION_RD3_VMC) != 0x30)
    389   1.1    sekiya 		  i++;
    390   1.1    sekiya 		dc->depth = 8 * i;
    391   1.1    sekiya 		dc->monitor =
    392   1.1    sekiya 			((bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD2) & 0x03) << 1) |
    393   1.1    sekiya 			(bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD1) & 0x01);
    394   1.1    sekiya 	} else {
    395   1.1    sekiya 		dc->backendrev = ~(bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD1)) & 0x03;
    396   1.1    sekiya 		if (dc->backendrev == 0)
    397   1.1    sekiya 			return;
    398   1.1    sekiya 		dc->zbuffer = bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD1) & GR2_REVISION4_RD1_ZBUFFER;
    399   1.1    sekiya 		dc->depth = ((bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD1) & GR2_REVISION4_RD1_24BPP) >> 4) ? 24 : 8;
    400   1.1    sekiya 		dc->monitor = (bus_space_read_4(dc->iot, dc->ioh, GR2_REVISION_RD0) & GR2_REVISION4_RD0_MONITOR_MASK) >> 4;
    401   1.1    sekiya 	}
    402   1.1    sekiya 
    403   1.1    sekiya 	dc->hq2rev = (bus_space_read_4(dc->iot, dc->ioh, HQ2_VERSION) & HQ2_VERSION_MASK) >> HQ2_VERSION_SHIFT;
    404   1.1    sekiya 	dc->ge7rev = (bus_space_read_4(dc->iot, dc->ioh, GE7_REVISION) & GE7_REVISION_MASK) >> 5;
    405   1.1    sekiya 	/* dc->vc1rev = vc1_read_ireg(dc, 5) & 0x07; */
    406   1.1    sekiya 
    407   1.1    sekiya 	/* gr2 supports 1280x1024 only */
    408   1.1    sekiya 	dc->xres = 1280;
    409   1.1    sekiya 	dc->yres = 1024;
    410   1.1    sekiya 
    411   1.1    sekiya #if 0
    412   1.1    sekiya 	/* Setup cursor glyph */
    413   1.1    sekiya 
    414   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_ADDRHI,
    415   1.1    sekiya 		(VC1_SRAM_CURSOR0_BASE >> 8) & 0xff);
    416   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_ADDRLO,
    417   1.1    sekiya 		VC1_SRAM_CURSOR0_BASE & 0xff);
    418   1.1    sekiya 	for (i = 0; i < 128; i++)
    419   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_SRAM, grtwo_cursor_data[i]);
    420   1.1    sekiya 
    421   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_ADDRHI,
    422   1.1    sekiya 		(VC1_CURSOR_EP >> 8) & 0xff);
    423   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_ADDRLO,
    424   1.1    sekiya 		VC1_CURSOR_EP & 0xff);
    425   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_COMMAND, VC1_SRAM_CURSOR0_BASE);
    426   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_COMMAND, 0);
    427   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_COMMAND, 0);
    428   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_COMMAND, 0);
    429   1.1    sekiya 
    430   1.1    sekiya 	/* Turn on cursor function, display, DID */
    431   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, VC1_SYSCTL,
    432   1.1    sekiya 		VC1_SYSCTL_VC1 | VC1_SYSCTL_DID |
    433   1.1    sekiya 		VC1_SYSCTL_CURSOR | VC1_SYSCTL_CURSOR_DISPLAY);
    434   1.1    sekiya #endif
    435   1.1    sekiya 
    436   1.1    sekiya 	/* Setup CMAP */
    437   1.1    sekiya 	for (i = 0; i < 8; i++)
    438   1.1    sekiya 		grtwo_cmap_setrgb(dc, i, grtwo_defcmap[i * 3],
    439   1.1    sekiya 			grtwo_defcmap[i * 3 + 1], grtwo_defcmap[i * 3 + 2]);
    440   1.1    sekiya }
    441   1.1    sekiya 
    442   1.1    sekiya /* Attach routines */
    443   1.1    sekiya static int
    444  1.13       chs grtwo_match(device_t parent, cfdata_t cf, void *aux)
    445   1.1    sekiya {
    446   1.1    sekiya 	struct gio_attach_args *ga = aux;
    447   1.1    sekiya 
    448   1.8    rumble 	if (ga->ga_addr != 0x1f000000 && ga->ga_addr != 0x1f400000 &&
    449   1.8    rumble 	    ga->ga_addr != 0x1f600000)
    450   1.8    rumble 		return (0);
    451   1.8    rumble 
    452   1.1    sekiya 	/*
    453   1.1    sekiya 	 * grtwo doesn't have anything that even vaguely resembles a product
    454   1.1    sekiya 	 * ID.  Instead, we determine presence by looking at the HQ2 "mystery"
    455   1.1    sekiya 	 * register, which contains a magic number.
    456   1.1    sekiya 	 */
    457   1.9    rumble 	if ( platform.badaddr((void *) (ga->ga_ioh + HQ2_MYSTERY),
    458   1.9    rumble 	    sizeof(u_int32_t)) )
    459   1.1    sekiya 		return 0;
    460   1.1    sekiya 
    461   1.1    sekiya 	if ( (bus_space_read_4(ga->ga_iot, ga->ga_ioh, HQ2_MYSTERY)) != 0xdeadbeef)
    462   1.1    sekiya 		return 0;
    463   1.1    sekiya 
    464   1.1    sekiya 	return 1;
    465   1.1    sekiya }
    466   1.1    sekiya 
    467   1.1    sekiya static void
    468   1.1    sekiya grtwo_attach_common(struct grtwo_devconfig * dc, struct gio_attach_args * ga)
    469   1.1    sekiya {
    470   1.1    sekiya 	dc->dc_addr = ga->ga_addr;
    471   1.1    sekiya 
    472   1.1    sekiya 	dc->iot = ga->ga_iot;
    473   1.1    sekiya 	dc->ioh = ga->ga_ioh;
    474   1.2    sekiya 	int i = 0;
    475   1.1    sekiya 
    476   1.1    sekiya 	wsfont_init();
    477   1.1    sekiya 
    478   1.1    sekiya 	dc->dc_font = wsfont_find(NULL, 8, 16, 0, WSDISPLAY_FONTORDER_L2R,
    479  1.12  macallan 				  WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP);
    480   1.1    sekiya 
    481   1.1    sekiya 	if (dc->dc_font < 0)
    482   1.1    sekiya 		panic("grtwo_attach_common: no suitable fonts");
    483   1.1    sekiya 
    484   1.1    sekiya 	if (wsfont_lock(dc->dc_font, &dc->dc_fontdata))
    485   1.1    sekiya 		panic("grtwo_attach_common: unable to lock font data");
    486   1.1    sekiya 
    487   1.1    sekiya 	grtwo_setup_hw(dc);
    488   1.1    sekiya 
    489   1.2    sekiya 	/* Large fills are broken.  For now, clear the screen line-by-line. */
    490   1.2    sekiya 	for (i = 0; i < 64; i++)
    491   1.2    sekiya 		grtwo_eraserows(dc, i, 1, 0);
    492   1.2    sekiya 
    493   1.2    sekiya 	/* If large fills worked, we'd do this instead:
    494   1.2    sekiya 	grtwo_fill_rectangle(dc, 0, 0, dc->xres - 1, dc->yres - 1, 0);
    495   1.2    sekiya 	*/
    496   1.1    sekiya }
    497   1.1    sekiya 
    498   1.1    sekiya static void
    499  1.13       chs grtwo_attach(device_t parent, device_t self, void *aux)
    500   1.1    sekiya {
    501   1.1    sekiya 	struct gio_attach_args *ga = aux;
    502  1.13       chs 	struct grtwo_softc *sc = device_private(self);
    503   1.1    sekiya 	struct wsemuldisplaydev_attach_args wa;
    504   1.1    sekiya 
    505   1.1    sekiya 	if (grtwo_is_console && ga->ga_addr == grtwo_console_dc.dc_addr) {
    506   1.1    sekiya 		wa.console = 1;
    507   1.1    sekiya 		sc->sc_dc = &grtwo_console_dc;
    508   1.1    sekiya 	} else {
    509   1.1    sekiya 		wa.console = 0;
    510   1.1    sekiya 		sc->sc_dc = malloc(sizeof(struct grtwo_devconfig),
    511   1.1    sekiya 				   M_DEVBUF, M_WAITOK | M_ZERO);
    512   1.1    sekiya 		if (sc->sc_dc == NULL)
    513   1.1    sekiya 			panic("grtwo_attach: out of memory");
    514   1.1    sekiya 
    515   1.1    sekiya 		grtwo_attach_common(sc->sc_dc, ga);
    516   1.1    sekiya 	}
    517   1.1    sekiya 
    518   1.1    sekiya 	aprint_naive(": Display adapter\n");
    519   1.1    sekiya 
    520   1.5    sekiya 	aprint_normal(": GR2 (board rev %x, monitor %d, depth %d)\n",
    521   1.1    sekiya 	      sc->sc_dc->boardrev, sc->sc_dc->monitor, sc->sc_dc->depth);
    522   1.1    sekiya 
    523   1.1    sekiya 	wa.scrdata = &grtwo_screenlist;
    524   1.1    sekiya 	wa.accessops = &grtwo_accessops;
    525   1.1    sekiya 	wa.accesscookie = sc->sc_dc;
    526   1.1    sekiya 
    527   1.2    sekiya         if ((cpu_intr_establish(0, IPL_TTY, grtwo_intr0, sc)) == NULL)
    528   1.2    sekiya                 printf(": unable to establish interrupt!\n");
    529   1.2    sekiya 
    530   1.2    sekiya         if ((cpu_intr_establish(6, IPL_TTY, grtwo_intr6, sc)) == NULL)
    531   1.2    sekiya                 printf(": unable to establish interrupt!\n");
    532   1.2    sekiya 
    533  1.13       chs 	config_found(self, &wa, wsemuldisplaydevprint);
    534   1.1    sekiya }
    535   1.1    sekiya 
    536   1.1    sekiya int
    537   1.1    sekiya grtwo_cnattach(struct gio_attach_args * ga)
    538   1.1    sekiya {
    539   1.1    sekiya 	long            defattr = GR2_ATTR_ENCODE(WSCOL_WHITE, WSCOL_BLACK);
    540   1.1    sekiya 
    541   1.1    sekiya 	if (!grtwo_match(NULL, NULL, ga)) {
    542   1.1    sekiya 		return ENXIO;
    543   1.1    sekiya 	}
    544   1.1    sekiya 
    545   1.1    sekiya 	grtwo_attach_common(&grtwo_console_dc, ga);
    546   1.4    sekiya 	wsdisplay_cnattach(&grtwo_screen, &grtwo_console_dc, 0, 0, defattr);
    547   1.1    sekiya 
    548   1.1    sekiya 	grtwo_is_console = 1;
    549   1.1    sekiya 
    550   1.1    sekiya 	return 0;
    551   1.1    sekiya }
    552   1.1    sekiya 
    553   1.1    sekiya /* wsdisplay textops */
    554   1.1    sekiya static void
    555   1.1    sekiya grtwo_cursor(void *c, int on, int row, int col)
    556   1.1    sekiya {
    557   1.1    sekiya 	struct grtwo_devconfig *dc = (void *) c;
    558   1.1    sekiya 	u_int32_t control;
    559   1.1    sekiya 	control = bus_space_read_4(dc->iot, dc->ioh, VC1_SYSCTL);
    560   1.1    sekiya 
    561   1.1    sekiya 	if (!on) {
    562   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_SYSCTL,
    563   1.1    sekiya 			control & ~VC1_SYSCTL_CURSOR_DISPLAY);
    564   1.1    sekiya 	} else {
    565   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_ADDRHI, (VC1_CURSOR_XL & 0xff00) >> 8
    566   1.1    sekiya 			);
    567   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_ADDRLO, VC1_CURSOR_XL & 0xff);
    568   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_COMMAND,
    569   1.1    sekiya 				  col * dc->dc_fontdata->fontwidth);
    570   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_COMMAND,
    571   1.1    sekiya 				  row * dc->dc_fontdata->fontheight);
    572   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, VC1_SYSCTL,
    573   1.1    sekiya 			control | VC1_SYSCTL_CURSOR_DISPLAY);
    574   1.1    sekiya 	}
    575   1.1    sekiya }
    576   1.1    sekiya 
    577   1.1    sekiya static int
    578   1.1    sekiya grtwo_mapchar(void *c, int ch, unsigned int *cp)
    579   1.1    sekiya {
    580   1.1    sekiya 	struct grtwo_devconfig *dc = (void *) c;
    581   1.1    sekiya 
    582   1.1    sekiya 	if (dc->dc_fontdata->encoding != WSDISPLAY_FONTENC_ISO) {
    583   1.1    sekiya 		ch = wsfont_map_unichar(dc->dc_fontdata, ch);
    584   1.1    sekiya 
    585   1.1    sekiya 		if (ch < 0)
    586   1.1    sekiya 			goto fail;
    587   1.1    sekiya 	}
    588   1.1    sekiya 	if (ch < dc->dc_fontdata->firstchar ||
    589   1.1    sekiya 	    ch >= dc->dc_fontdata->firstchar + dc->dc_fontdata->numchars)
    590   1.1    sekiya 		goto fail;
    591   1.1    sekiya 
    592   1.1    sekiya 	*cp = ch;
    593   1.1    sekiya 	return 5;
    594   1.1    sekiya 
    595   1.1    sekiya fail:
    596   1.1    sekiya 	*cp = ' ';
    597   1.1    sekiya 	return 0;
    598   1.1    sekiya }
    599   1.1    sekiya 
    600   1.1    sekiya static void
    601   1.1    sekiya grtwo_putchar(void *c, int row, int col, u_int ch, long attr)
    602   1.1    sekiya {
    603   1.1    sekiya 	struct grtwo_devconfig *dc = (void *) c;
    604   1.1    sekiya 	struct wsdisplay_font *font = dc->dc_fontdata;
    605   1.2    sekiya 	u_int8_t        *bitmap = (u_int8_t *) font->data + (ch - font->firstchar + 1) * font->fontheight * font->stride;
    606   1.1    sekiya 	u_int32_t        pattern;
    607   1.1    sekiya 	int             i;
    608   1.1    sekiya 	int             x = col * font->fontwidth;
    609   1.1    sekiya 	int             y = dc->yres - ( (row + 1) * font->fontheight);
    610   1.1    sekiya 
    611   1.1    sekiya 	/* Set the drawing color */
    612   1.1    sekiya 	grtwo_wait_gfifo(dc);
    613   1.2    sekiya 	grtwo_set_color(dc->iot, dc->ioh, (((attr) >> 8) & 0xff));
    614   1.2    sekiya 	grtwo_wait_gfifo(dc);
    615   1.1    sekiya 
    616   1.1    sekiya 	/* Set drawing coordinates */
    617   1.1    sekiya 	grtwo_wait_gfifo(dc);
    618   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_CMOV2I, x);
    619   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, y);
    620   1.1    sekiya 
    621   1.2    sekiya 	/* This works for font sizes < 18 */
    622   1.1    sekiya 	grtwo_wait_gfifo(dc);
    623   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DRAWCHAR, font->fontwidth);
    624   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, font->fontheight);
    625   1.2    sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, 2);
    626   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, 0); /* x offset */
    627   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, 0); /* y offset */
    628   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, 0);
    629   1.1    sekiya 	bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, 0);
    630   1.1    sekiya 
    631   1.1    sekiya 	for (i = 0; i < font->fontheight; i++) {
    632   1.1    sekiya 		/* It appears that writes have to be 16 bits.  An "I tell you
    633   1.1    sekiya 		   two times" sort of thing?  Thanks, SGI */
    634   1.1    sekiya 		pattern = *bitmap | (*bitmap << 8);
    635   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, pattern);
    636   1.2    sekiya 		bitmap -= font->stride;
    637   1.1    sekiya 	}
    638   1.1    sekiya 
    639   1.1    sekiya 	/* pad up to 18 */
    640   1.1    sekiya 	for (i = font->fontheight; i < 18; i++)
    641   1.1    sekiya 		bus_space_write_4(dc->iot, dc->ioh, GR2_FIFO_DATA, 0x0000);
    642   1.1    sekiya }
    643   1.1    sekiya 
    644   1.1    sekiya static void
    645   1.1    sekiya grtwo_copycols(void *c, int row, int srccol, int dstcol, int ncols)
    646   1.1    sekiya {
    647   1.2    sekiya #if 1
    648   1.2    sekiya 	printf("grtwo_copycols: %i %i %i %i\n", row, srccol, dstcol, ncols);
    649   1.2    sekiya #else
    650   1.1    sekiya 	struct grtwo_devconfig *dc = (void *) c;
    651   1.1    sekiya 	struct wsdisplay_font *font = dc->dc_fontdata;
    652   1.1    sekiya 	grtwo_copy_rectangle(dc,
    653   1.1    sekiya 			     srccol * font->fontwidth,	/* x1 */
    654   1.2    sekiya 			     0,	/* y1 */
    655   1.2    sekiya 			     dstcol * font->fontwidth,	/* x2 */
    656   1.2    sekiya 			     0,	/* y2 */
    657   1.2    sekiya 			     ncols * font->fontwidth,	/* dx */
    658   1.2    sekiya 			     dc->yres );	/* dy */
    659   1.2    sekiya #endif
    660   1.1    sekiya }
    661   1.1    sekiya 
    662   1.1    sekiya static void
    663   1.1    sekiya grtwo_erasecols(void *c, int row, int startcol, int ncols, long attr)
    664   1.1    sekiya {
    665   1.1    sekiya 	struct grtwo_devconfig *dc = (void *) c;
    666   1.1    sekiya 	struct wsdisplay_font *font = dc->dc_fontdata;
    667   1.1    sekiya 
    668   1.1    sekiya 	grtwo_fill_rectangle(dc,
    669   1.1    sekiya 			     startcol * font->fontwidth,	/* x1 */
    670   1.2    sekiya 			     0,	/* y1 */
    671   1.2    sekiya 			     (startcol * font->fontwidth) + ncols * font->fontwidth,	/* x2 */
    672   1.2    sekiya 			     dc->yres,	/* y2 */
    673   1.1    sekiya 			     GR2_ATTR_BG(attr));
    674   1.1    sekiya }
    675   1.1    sekiya 
    676   1.1    sekiya static void
    677   1.1    sekiya grtwo_copyrows(void *c, int srcrow, int dstrow, int nrows)
    678   1.1    sekiya {
    679   1.1    sekiya 	struct grtwo_devconfig *dc = (void *) c;
    680   1.1    sekiya 	struct wsdisplay_font *font = dc->dc_fontdata;
    681   1.1    sekiya 
    682   1.1    sekiya 	grtwo_copy_rectangle(dc,
    683   1.1    sekiya 			     0,	/* x1 */
    684   1.1    sekiya 			     srcrow * font->fontheight,	/* y1 */
    685   1.2    sekiya 			     0, /* x2 */
    686   1.2    sekiya 			     dstrow * font->fontheight,	/* y2 */
    687   1.2    sekiya 			     dc->xres,	/* dx */
    688   1.2    sekiya 			     nrows * font->fontheight);
    689   1.1    sekiya }
    690   1.1    sekiya 
    691   1.1    sekiya static void
    692   1.1    sekiya grtwo_eraserows(void *c, int startrow, int nrows, long attr)
    693   1.1    sekiya {
    694   1.1    sekiya 	struct grtwo_devconfig *dc = (void *) c;
    695   1.1    sekiya 	struct wsdisplay_font *font = dc->dc_fontdata;
    696   1.1    sekiya 	grtwo_fill_rectangle(dc,
    697   1.1    sekiya 			     0,	/* x1 */
    698   1.1    sekiya 			     startrow * font->fontheight,	/* y1 */
    699   1.1    sekiya 			     dc->xres,	/* x2 */
    700   1.2    sekiya 			     (startrow * font->fontheight) + nrows * font->fontheight,	/* y2 */
    701   1.1    sekiya 			     GR2_ATTR_BG(attr));
    702   1.1    sekiya }
    703   1.1    sekiya 
    704   1.1    sekiya static int
    705   1.1    sekiya grtwo_allocattr(void *c, int fg, int bg, int flags, long *attr)
    706   1.1    sekiya {
    707   1.1    sekiya 	if (flags & WSATTR_BLINK)
    708   1.1    sekiya 		return EINVAL;
    709   1.1    sekiya 
    710   1.1    sekiya 	if ((flags & WSATTR_WSCOLORS) == 0) {
    711   1.1    sekiya 		fg = WSCOL_WHITE;
    712   1.1    sekiya 		bg = WSCOL_BLACK;
    713   1.1    sekiya 	}
    714   1.1    sekiya 	if (flags & WSATTR_HILIT)
    715   1.1    sekiya 		fg += 8;
    716   1.1    sekiya 
    717   1.1    sekiya 	if (flags & WSATTR_REVERSE) {
    718   1.1    sekiya 		int             tmp = fg;
    719   1.1    sekiya 		fg = bg;
    720   1.1    sekiya 		bg = tmp;
    721   1.1    sekiya 	}
    722   1.1    sekiya 	*attr = GR2_ATTR_ENCODE(fg, bg);
    723   1.1    sekiya 
    724   1.1    sekiya 	return 0;
    725   1.1    sekiya }
    726   1.1    sekiya 
    727   1.1    sekiya /* wsdisplay accessops */
    728   1.1    sekiya 
    729   1.1    sekiya static int
    730  1.10  christos grtwo_ioctl(void *c, void *vs, u_long cmd, void *data, int flag,
    731   1.7      jmmv 	struct lwp *l)
    732   1.1    sekiya {
    733   1.1    sekiya 	struct grtwo_softc *sc = c;
    734   1.1    sekiya 
    735   1.1    sekiya #define FBINFO (*(struct wsdisplay_fbinfo*)data)
    736   1.1    sekiya 
    737   1.1    sekiya 	switch (cmd) {
    738   1.1    sekiya 	case WSDISPLAYIO_GINFO:
    739   1.1    sekiya 		FBINFO.width = sc->sc_dc->xres;
    740   1.1    sekiya 		FBINFO.height = sc->sc_dc->yres;
    741   1.1    sekiya 		FBINFO.depth = sc->sc_dc->depth;
    742   1.1    sekiya 		FBINFO.cmsize = 1 << FBINFO.depth;
    743   1.1    sekiya 		return 0;
    744   1.1    sekiya 	case WSDISPLAYIO_GTYPE:
    745   1.1    sekiya 		*(u_int *) data = WSDISPLAY_TYPE_GR2;
    746   1.1    sekiya 		return 0;
    747   1.1    sekiya 	}
    748   1.1    sekiya 	return EPASSTHROUGH;
    749   1.1    sekiya }
    750   1.1    sekiya 
    751   1.1    sekiya static          paddr_t
    752   1.7      jmmv grtwo_mmap(void *c, void *vs, off_t offset, int prot)
    753   1.1    sekiya {
    754   1.1    sekiya 	struct grtwo_devconfig *dc = c;
    755   1.1    sekiya 
    756   1.1    sekiya 	if (offset >= 0xfffff)
    757   1.1    sekiya 		return -1;
    758   1.1    sekiya 
    759   1.1    sekiya 	return mips_btop(dc->dc_addr + offset);
    760   1.1    sekiya }
    761   1.1    sekiya 
    762   1.1    sekiya static int
    763   1.1    sekiya grtwo_alloc_screen(void *c, const struct wsscreen_descr * type, void **cookiep,
    764   1.1    sekiya 		   int *cursxp, int *cursyp, long *attrp)
    765   1.1    sekiya {
    766   1.1    sekiya 	/*
    767   1.1    sekiya 	 * This won't get called for console screen and we don't support
    768   1.1    sekiya 	 * virtual screens
    769   1.1    sekiya 	 */
    770   1.1    sekiya 
    771   1.1    sekiya 	return ENOMEM;
    772   1.1    sekiya }
    773   1.1    sekiya 
    774   1.1    sekiya static void
    775   1.1    sekiya grtwo_free_screen(void *c, void *cookie)
    776   1.1    sekiya {
    777   1.1    sekiya 	panic("grtwo_free_screen");
    778   1.1    sekiya }
    779   1.1    sekiya static int
    780   1.1    sekiya grtwo_show_screen(void *c, void *cookie, int waitok,
    781   1.1    sekiya 		  void (*cb) (void *, int, int), void *cbarg)
    782   1.1    sekiya {
    783   1.1    sekiya 	return 0;
    784   1.1    sekiya }
    785   1.2    sekiya 
    786   1.2    sekiya static int
    787   1.2    sekiya grtwo_intr0(void *arg)
    788   1.2    sekiya {
    789   1.2    sekiya 	/* struct grtwo_devconfig *dc = arg; */
    790   1.2    sekiya 	return 1;
    791   1.2    sekiya }
    792   1.2    sekiya 
    793   1.2    sekiya 
    794   1.2    sekiya static int
    795   1.2    sekiya grtwo_intr6(void *arg)
    796   1.2    sekiya {
    797   1.2    sekiya 	/* struct grtwo_devconfig *dc = arg; */
    798   1.2    sekiya 	return 1;
    799   1.2    sekiya }
    800   1.2    sekiya 
    801