Home | History | Annotate | Line # | Download | only in sun
cgsix.c revision 1.68
      1  1.68  macallan /*	$NetBSD: cgsix.c,v 1.68 2019/01/19 00:16:43 macallan Exp $ */
      2   1.1        pk 
      3   1.1        pk /*-
      4   1.1        pk  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5   1.1        pk  * All rights reserved.
      6   1.1        pk  *
      7   1.1        pk  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1        pk  * by Paul Kranenburg.
      9   1.1        pk  *
     10   1.1        pk  * Redistribution and use in source and binary forms, with or without
     11   1.1        pk  * modification, are permitted provided that the following conditions
     12   1.1        pk  * are met:
     13   1.1        pk  * 1. Redistributions of source code must retain the above copyright
     14   1.1        pk  *    notice, this list of conditions and the following disclaimer.
     15   1.1        pk  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1        pk  *    notice, this list of conditions and the following disclaimer in the
     17   1.1        pk  *    documentation and/or other materials provided with the distribution.
     18   1.1        pk  *
     19   1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1        pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1        pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1        pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1        pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1        pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1        pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1        pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1        pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1        pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1        pk  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1        pk  */
     31   1.1        pk 
     32   1.1        pk /*
     33   1.1        pk  * Copyright (c) 1993
     34   1.1        pk  *	The Regents of the University of California.  All rights reserved.
     35   1.1        pk  *
     36   1.1        pk  * This software was developed by the Computer Systems Engineering group
     37   1.1        pk  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     38   1.1        pk  * contributed to Berkeley.
     39   1.1        pk  *
     40   1.1        pk  * All advertising materials mentioning features or use of this software
     41   1.1        pk  * must display the following acknowledgement:
     42   1.1        pk  *	This product includes software developed by the University of
     43   1.1        pk  *	California, Lawrence Berkeley Laboratory.
     44   1.1        pk  *
     45   1.1        pk  * Redistribution and use in source and binary forms, with or without
     46   1.1        pk  * modification, are permitted provided that the following conditions
     47   1.1        pk  * are met:
     48   1.1        pk  * 1. Redistributions of source code must retain the above copyright
     49   1.1        pk  *    notice, this list of conditions and the following disclaimer.
     50   1.1        pk  * 2. Redistributions in binary form must reproduce the above copyright
     51   1.1        pk  *    notice, this list of conditions and the following disclaimer in the
     52   1.1        pk  *    documentation and/or other materials provided with the distribution.
     53  1.13       agc  * 3. Neither the name of the University nor the names of its contributors
     54   1.1        pk  *    may be used to endorse or promote products derived from this software
     55   1.1        pk  *    without specific prior written permission.
     56   1.1        pk  *
     57   1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     58   1.1        pk  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     59   1.1        pk  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     60   1.1        pk  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     61   1.1        pk  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     62   1.1        pk  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     63   1.1        pk  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     64   1.1        pk  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     65   1.1        pk  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     66   1.1        pk  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     67   1.1        pk  * SUCH DAMAGE.
     68   1.1        pk  *
     69   1.1        pk  *	@(#)cgsix.c	8.4 (Berkeley) 1/21/94
     70   1.1        pk  */
     71   1.1        pk 
     72   1.1        pk /*
     73   1.1        pk  * color display (cgsix) driver.
     74   1.1        pk  *
     75   1.1        pk  * Does not handle interrupts, even though they can occur.
     76   1.1        pk  *
     77   1.1        pk  * XXX should defer colormap updates to vertical retrace interrupts
     78   1.1        pk  */
     79   1.7     lukem 
     80   1.7     lukem #include <sys/cdefs.h>
     81  1.68  macallan __KERNEL_RCSID(0, "$NetBSD: cgsix.c,v 1.68 2019/01/19 00:16:43 macallan Exp $");
     82   1.1        pk 
     83   1.1        pk #include <sys/param.h>
     84   1.1        pk #include <sys/systm.h>
     85   1.1        pk #include <sys/buf.h>
     86   1.1        pk #include <sys/device.h>
     87   1.1        pk #include <sys/ioctl.h>
     88   1.1        pk #include <sys/malloc.h>
     89   1.1        pk #include <sys/mman.h>
     90   1.1        pk #include <sys/tty.h>
     91   1.1        pk #include <sys/conf.h>
     92   1.1        pk 
     93   1.1        pk #ifdef DEBUG
     94   1.1        pk #include <sys/proc.h>
     95   1.1        pk #include <sys/syslog.h>
     96   1.1        pk #endif
     97   1.1        pk 
     98  1.35        ad #include <sys/bus.h>
     99   1.1        pk 
    100   1.1        pk #include <dev/sun/fbio.h>
    101   1.1        pk #include <dev/sun/fbvar.h>
    102   1.1        pk 
    103   1.1        pk #include <dev/sun/btreg.h>
    104   1.1        pk #include <dev/sun/btvar.h>
    105   1.1        pk #include <dev/sun/pfourreg.h>
    106   1.1        pk 
    107  1.18    martin #include <dev/wscons/wsconsio.h>
    108  1.18    martin #include <dev/wsfont/wsfont.h>
    109   1.1        pk #include <dev/rasops/rasops.h>
    110  1.18    martin 
    111  1.18    martin #include "opt_wsemul.h"
    112  1.20    martin #include "rasops_glue.h"
    113   1.1        pk 
    114  1.23  macallan #include <dev/sun/cgsixreg.h>
    115  1.23  macallan #include <dev/sun/cgsixvar.h>
    116  1.23  macallan 
    117  1.46   tsutsui #include "ioconf.h"
    118  1.46   tsutsui 
    119  1.39  macallan static void	cg6_unblank(device_t);
    120  1.33  macallan static void	cg6_blank(struct cgsix_softc *, int);
    121   1.1        pk 
    122   1.8   gehenna dev_type_open(cgsixopen);
    123   1.8   gehenna dev_type_close(cgsixclose);
    124   1.8   gehenna dev_type_ioctl(cgsixioctl);
    125   1.8   gehenna dev_type_mmap(cgsixmmap);
    126   1.8   gehenna 
    127   1.8   gehenna const struct cdevsw cgsix_cdevsw = {
    128  1.64  dholland 	.d_open = cgsixopen,
    129  1.64  dholland 	.d_close = cgsixclose,
    130  1.64  dholland 	.d_read = noread,
    131  1.64  dholland 	.d_write = nowrite,
    132  1.64  dholland 	.d_ioctl = cgsixioctl,
    133  1.64  dholland 	.d_stop = nostop,
    134  1.64  dholland 	.d_tty = notty,
    135  1.64  dholland 	.d_poll = nopoll,
    136  1.64  dholland 	.d_mmap = cgsixmmap,
    137  1.64  dholland 	.d_kqfilter = nokqfilter,
    138  1.65  dholland 	.d_discard = nodiscard,
    139  1.64  dholland 	.d_flag = D_OTHER
    140   1.8   gehenna };
    141   1.1        pk 
    142   1.1        pk /* frame buffer generic driver */
    143   1.1        pk static struct fbdriver cg6_fbdriver = {
    144   1.9  jdolecek 	cg6_unblank, cgsixopen, cgsixclose, cgsixioctl, nopoll, cgsixmmap,
    145   1.9  jdolecek 	nokqfilter
    146   1.1        pk };
    147   1.1        pk 
    148   1.1        pk static void cg6_reset (struct cgsix_softc *);
    149   1.1        pk static void cg6_loadcmap (struct cgsix_softc *, int, int);
    150   1.1        pk static void cg6_loadomap (struct cgsix_softc *);
    151   1.1        pk static void cg6_setcursor (struct cgsix_softc *);/* set position */
    152   1.1        pk static void cg6_loadcursor (struct cgsix_softc *);/* set shape */
    153   1.1        pk 
    154  1.23  macallan static void cg6_setup_palette(struct cgsix_softc *);
    155  1.23  macallan 
    156  1.18    martin struct wsscreen_descr cgsix_defaultscreen = {
    157  1.18    martin 	"std",
    158  1.18    martin 	0, 0,	/* will be filled in -- XXX shouldn't, it's global */
    159  1.23  macallan 	NULL,		/* textops */
    160  1.23  macallan 	8, 16,	/* font width/height */
    161  1.68  macallan 	WSSCREEN_WSCOLORS | WSSCREEN_RESIZE | WSSCREEN_UNDERLINE,
    162  1.32    martin 	NULL	/* modecookie */
    163  1.18    martin };
    164  1.18    martin 
    165  1.34  christos static int 	cgsix_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    166  1.30      jmmv static paddr_t	cgsix_mmap(void *, void *, off_t, int);
    167  1.33  macallan static void	cgsix_init_screen(void *, struct vcons_screen *, int, long *);
    168  1.33  macallan 
    169  1.33  macallan static void	cgsix_clearscreen(struct cgsix_softc *);
    170  1.23  macallan 
    171  1.23  macallan void 	cgsix_setup_mono(struct cgsix_softc *, int, int, int, int, uint32_t,
    172  1.23  macallan 		uint32_t);
    173  1.23  macallan void 	cgsix_feed_line(struct cgsix_softc *, int, uint8_t *);
    174  1.23  macallan void 	cgsix_rectfill(struct cgsix_softc *, int, int, int, int, uint32_t);
    175  1.57  macallan void	cgsix_bitblt(void *, int, int, int, int, int, int, int);
    176  1.23  macallan 
    177  1.23  macallan int	cgsix_putcmap(struct cgsix_softc *, struct wsdisplay_cmap *);
    178  1.23  macallan int	cgsix_getcmap(struct cgsix_softc *, struct wsdisplay_cmap *);
    179  1.23  macallan void	cgsix_putchar(void *, int, int, u_int, long);
    180  1.57  macallan void	cgsix_putchar_aa(void *, int, int, u_int, long);
    181  1.23  macallan void	cgsix_cursor(void *, int, int, int);
    182  1.23  macallan 
    183  1.18    martin struct wsdisplay_accessops cgsix_accessops = {
    184  1.18    martin 	cgsix_ioctl,
    185  1.18    martin 	cgsix_mmap,
    186  1.33  macallan 	NULL,	/* alloc_screen */
    187  1.33  macallan 	NULL,	/* free_screen */
    188  1.33  macallan 	NULL,	/* show_screen */
    189  1.18    martin 	NULL, 	/* load_font */
    190  1.18    martin 	NULL,	/* pollc */
    191  1.18    martin 	NULL	/* scroll */
    192  1.18    martin };
    193  1.18    martin 
    194  1.18    martin const struct wsscreen_descr *_cgsix_scrlist[] = {
    195  1.18    martin 	&cgsix_defaultscreen
    196  1.18    martin };
    197  1.18    martin 
    198  1.18    martin struct wsscreen_list cgsix_screenlist = {
    199  1.18    martin 	sizeof(_cgsix_scrlist) / sizeof(struct wsscreen_descr *),
    200  1.18    martin 	_cgsix_scrlist
    201  1.18    martin };
    202  1.18    martin 
    203  1.23  macallan 
    204  1.23  macallan extern const u_char rasops_cmap[768];
    205  1.23  macallan 
    206  1.23  macallan void	cg6_invert(struct cgsix_softc *, int, int, int, int);
    207  1.23  macallan 
    208  1.33  macallan static struct vcons_screen cg6_console_screen;
    209   1.1        pk 
    210   1.1        pk /*
    211   1.1        pk  * cg6 accelerated console routines.
    212   1.1        pk  *
    213   1.1        pk  * Note that buried in this code in several places is the assumption
    214   1.1        pk  * that pixels are exactly one byte wide.  Since this is cg6-specific
    215   1.1        pk  * code, this seems safe.  This assumption resides in things like the
    216   1.1        pk  * use of ri_emuwidth without messing around with ri_pelbytes, or the
    217   1.1        pk  * assumption that ri_font->fontwidth is the right thing to multiply
    218   1.1        pk  * character-cell counts by to get byte counts.
    219   1.1        pk  */
    220   1.1        pk 
    221   1.1        pk /*
    222   1.1        pk  * Magic values for blitter
    223   1.1        pk  */
    224   1.1        pk 
    225   1.5   tsutsui /* Values for the mode register */
    226   1.5   tsutsui #define CG6_MODE	(						\
    227   1.5   tsutsui 	  0x00200000 /* GX_BLIT_SRC */					\
    228   1.5   tsutsui 	| 0x00020000 /* GX_MODE_COLOR8 */				\
    229   1.5   tsutsui 	| 0x00008000 /* GX_DRAW_RENDER */				\
    230   1.5   tsutsui 	| 0x00002000 /* GX_BWRITE0_ENABLE */				\
    231   1.5   tsutsui 	| 0x00001000 /* GX_BWRITE1_DISABLE */				\
    232   1.5   tsutsui 	| 0x00000200 /* GX_BREAD_0 */					\
    233   1.5   tsutsui 	| 0x00000080 /* GX_BDISP_0 */					\
    234   1.5   tsutsui )
    235   1.5   tsutsui #define CG6_MODE_MASK	(						\
    236   1.5   tsutsui 	  0x00300000 /* GX_BLIT_ALL */					\
    237   1.5   tsutsui 	| 0x00060000 /* GX_MODE_ALL */					\
    238   1.5   tsutsui 	| 0x00018000 /* GX_DRAW_ALL */					\
    239   1.5   tsutsui 	| 0x00006000 /* GX_BWRITE0_ALL */				\
    240   1.5   tsutsui 	| 0x00001800 /* GX_BWRITE1_ALL */				\
    241   1.5   tsutsui 	| 0x00000600 /* GX_BREAD_ALL */					\
    242   1.5   tsutsui 	| 0x00000180 /* GX_BDISP_ALL */					\
    243   1.5   tsutsui )
    244   1.5   tsutsui 
    245   1.1        pk /* Value for the alu register for screen-to-screen copies */
    246   1.1        pk #define CG6_ALU_COPY	(						\
    247   1.1        pk 	  0x80000000 /* GX_PLANE_ONES (ignore planemask register) */	\
    248   1.1        pk 	| 0x20000000 /* GX_PIXEL_ONES (ignore pixelmask register) */	\
    249   1.1        pk 	| 0x00800000 /* GX_ATTR_SUPP (function unknown) */		\
    250   1.1        pk 	| 0x00000000 /* GX_RAST_BOOL (function unknown) */		\
    251   1.1        pk 	| 0x00000000 /* GX_PLOT_PLOT (function unknown) */		\
    252   1.1        pk 	| 0x08000000 /* GX_PATTERN_ONES (ignore pattern) */		\
    253   1.1        pk 	| 0x01000000 /* GX_POLYG_OVERLAP (unsure - handle overlap?) */	\
    254   1.1        pk 	| 0x0000cccc /* ALU = src */					\
    255   1.1        pk )
    256   1.1        pk 
    257   1.1        pk /* Value for the alu register for region fills */
    258   1.1        pk #define CG6_ALU_FILL	(						\
    259   1.1        pk 	  0x80000000 /* GX_PLANE_ONES (ignore planemask register) */	\
    260   1.1        pk 	| 0x20000000 /* GX_PIXEL_ONES (ignore pixelmask register) */	\
    261   1.1        pk 	| 0x00800000 /* GX_ATTR_SUPP (function unknown) */		\
    262   1.1        pk 	| 0x00000000 /* GX_RAST_BOOL (function unknown) */		\
    263   1.1        pk 	| 0x00000000 /* GX_PLOT_PLOT (function unknown) */		\
    264   1.1        pk 	| 0x08000000 /* GX_PATTERN_ONES (ignore pattern) */		\
    265   1.1        pk 	| 0x01000000 /* GX_POLYG_OVERLAP (unsure - handle overlap?) */	\
    266   1.1        pk 	| 0x0000ff00 /* ALU = fg color */				\
    267   1.1        pk )
    268   1.1        pk 
    269   1.1        pk /* Value for the alu register for toggling an area */
    270   1.1        pk #define CG6_ALU_FLIP	(						\
    271   1.1        pk 	  0x80000000 /* GX_PLANE_ONES (ignore planemask register) */	\
    272   1.1        pk 	| 0x20000000 /* GX_PIXEL_ONES (ignore pixelmask register) */	\
    273   1.1        pk 	| 0x00800000 /* GX_ATTR_SUPP (function unknown) */		\
    274   1.1        pk 	| 0x00000000 /* GX_RAST_BOOL (function unknown) */		\
    275   1.1        pk 	| 0x00000000 /* GX_PLOT_PLOT (function unknown) */		\
    276   1.1        pk 	| 0x08000000 /* GX_PATTERN_ONES (ignore pattern) */		\
    277   1.1        pk 	| 0x01000000 /* GX_POLYG_OVERLAP (unsure - handle overlap?) */	\
    278   1.1        pk 	| 0x00005555 /* ALU = ~dst */					\
    279   1.1        pk )
    280   1.1        pk 
    281   1.1        pk /*
    282  1.56  macallan  * Run a blitter command
    283   1.1        pk  */
    284  1.62    martin #define CG6_BLIT(f) { (void)f->fbc_blit; }
    285   1.1        pk 
    286   1.1        pk /*
    287  1.56  macallan  * Run a drawing command
    288   1.1        pk  */
    289  1.62    martin #define CG6_DRAW(f) { (void)f->fbc_draw; }
    290   1.1        pk 
    291   1.1        pk /*
    292   1.1        pk  * Wait for the whole engine to go idle.  This may not matter in our case;
    293   1.1        pk  * I'm not sure whether blits are actually queued or not.  It more likely
    294   1.1        pk  * is intended for lines and such that do get queued.
    295   1.1        pk  * 0x10000000 bit: GX_INPROGRESS
    296   1.1        pk  */
    297   1.1        pk #define CG6_DRAIN(fbc) do {						\
    298  1.56  macallan 	while ((fbc)->fbc_s & GX_INPROGRESS)				\
    299  1.56  macallan 		/*EMPTY*/;						\
    300  1.56  macallan } while (0)
    301  1.56  macallan 
    302  1.58  macallan /*
    303  1.58  macallan  * something is missing here
    304  1.58  macallan  * Waiting for GX_FULL to clear should be enough to send another command
    305  1.58  macallan  * but some CG6 ( LX onboard for example ) lock up if we do that while
    306  1.58  macallan  * it works fine on others ( a 4MB TGX+ I've got here )
    307  1.58  macallan  * So, until I figure out what's going on we wait for the blitter to go
    308  1.58  macallan  * fully idle.
    309  1.58  macallan  */
    310  1.56  macallan #define CG6_WAIT_READY(fbc) do {					\
    311  1.58  macallan        	while (((fbc)->fbc_s & GX_INPROGRESS/*GX_FULL*/) != 0)		\
    312   1.1        pk 		/*EMPTY*/;						\
    313   1.1        pk } while (0)
    314   1.1        pk 
    315   1.5   tsutsui static void cg6_ras_init(struct cgsix_softc *);
    316   1.5   tsutsui static void cg6_ras_copyrows(void *, int, int, int);
    317   1.5   tsutsui static void cg6_ras_copycols(void *, int, int, int, int);
    318   1.5   tsutsui static void cg6_ras_erasecols(void *, int, int, int, long int);
    319   1.5   tsutsui static void cg6_ras_eraserows(void *, int, int, long int);
    320  1.55  macallan 
    321   1.5   tsutsui static void
    322   1.5   tsutsui cg6_ras_init(struct cgsix_softc *sc)
    323   1.5   tsutsui {
    324   1.5   tsutsui 	volatile struct cg6_fbc *fbc = sc->sc_fbc;
    325   1.5   tsutsui 
    326   1.5   tsutsui 	CG6_DRAIN(fbc);
    327   1.5   tsutsui 	fbc->fbc_mode &= ~CG6_MODE_MASK;
    328   1.5   tsutsui 	fbc->fbc_mode |= CG6_MODE;
    329  1.55  macallan 
    330  1.55  macallan 	/* set some common drawing engine parameters */
    331  1.55  macallan 	fbc->fbc_clip = 0;
    332  1.55  macallan 	fbc->fbc_s = 0;
    333  1.55  macallan 	fbc->fbc_offx = 0;
    334  1.55  macallan 	fbc->fbc_offy = 0;
    335  1.55  macallan 	fbc->fbc_clipminx = 0;
    336  1.55  macallan 	fbc->fbc_clipminy = 0;
    337  1.55  macallan 	fbc->fbc_clipmaxx = 0x3fff;
    338  1.55  macallan 	fbc->fbc_clipmaxy = 0x3fff;
    339   1.5   tsutsui }
    340   1.5   tsutsui 
    341   1.1        pk static void
    342   1.1        pk cg6_ras_copyrows(void *cookie, int src, int dst, int n)
    343   1.1        pk {
    344  1.33  macallan 	struct rasops_info *ri = cookie;
    345  1.33  macallan 	struct vcons_screen *scr = ri->ri_hw;
    346  1.33  macallan 	struct cgsix_softc *sc = scr->scr_cookie;
    347  1.33  macallan 	volatile struct cg6_fbc *fbc = sc->sc_fbc;
    348  1.23  macallan 
    349  1.33  macallan 	if (dst == src)
    350  1.33  macallan 		return;
    351  1.33  macallan 	if (src < 0) {
    352  1.33  macallan 		n += src;
    353  1.33  macallan 		src = 0;
    354  1.33  macallan 	}
    355  1.33  macallan 	if (src+n > ri->ri_rows)
    356  1.33  macallan 		n = ri->ri_rows - src;
    357  1.33  macallan 	if (dst < 0) {
    358  1.33  macallan 		n += dst;
    359  1.33  macallan 		dst = 0;
    360  1.33  macallan 	}
    361  1.33  macallan 	if (dst+n > ri->ri_rows)
    362  1.33  macallan 		n = ri->ri_rows - dst;
    363  1.33  macallan 	if (n <= 0)
    364  1.33  macallan 		return;
    365  1.33  macallan 	n *= ri->ri_font->fontheight;
    366  1.33  macallan 	src *= ri->ri_font->fontheight;
    367  1.33  macallan 	dst *= ri->ri_font->fontheight;
    368  1.55  macallan 
    369  1.56  macallan 	CG6_WAIT_READY(fbc);
    370  1.56  macallan 
    371  1.33  macallan 	fbc->fbc_alu = CG6_ALU_COPY;
    372  1.55  macallan 	fbc->fbc_mode = GX_BLIT_SRC | GX_MODE_COLOR8;
    373  1.55  macallan 
    374  1.33  macallan 	fbc->fbc_x0 = ri->ri_xorigin;
    375  1.33  macallan 	fbc->fbc_y0 = ri->ri_yorigin + src;
    376  1.33  macallan 	fbc->fbc_x1 = ri->ri_xorigin + ri->ri_emuwidth - 1;
    377  1.33  macallan 	fbc->fbc_y1 = ri->ri_yorigin + src + n - 1;
    378  1.33  macallan 	fbc->fbc_x2 = ri->ri_xorigin;
    379  1.33  macallan 	fbc->fbc_y2 = ri->ri_yorigin + dst;
    380  1.33  macallan 	fbc->fbc_x3 = ri->ri_xorigin + ri->ri_emuwidth - 1;
    381  1.33  macallan 	fbc->fbc_y3 = ri->ri_yorigin + dst + n - 1;
    382  1.56  macallan 	CG6_BLIT(fbc);
    383   1.1        pk }
    384   1.1        pk 
    385   1.1        pk static void
    386   1.1        pk cg6_ras_copycols(void *cookie, int row, int src, int dst, int n)
    387   1.1        pk {
    388  1.33  macallan 	struct rasops_info *ri = cookie;
    389  1.33  macallan 	struct vcons_screen *scr = ri->ri_hw;
    390  1.33  macallan 	struct cgsix_softc *sc = scr->scr_cookie;
    391  1.33  macallan 	volatile struct cg6_fbc *fbc = sc->sc_fbc;
    392  1.23  macallan 
    393  1.33  macallan 	if (dst == src)
    394  1.33  macallan 		return;
    395  1.33  macallan 	if ((row < 0) || (row >= ri->ri_rows))
    396  1.33  macallan 		return;
    397  1.33  macallan 	if (src < 0) {
    398  1.33  macallan 		n += src;
    399  1.33  macallan 		src = 0;
    400  1.33  macallan 	}
    401  1.33  macallan 	if (src+n > ri->ri_cols)
    402  1.33  macallan 		n = ri->ri_cols - src;
    403  1.33  macallan 	if (dst < 0) {
    404  1.33  macallan 		n += dst;
    405  1.33  macallan 		dst = 0;
    406  1.33  macallan 	}
    407  1.33  macallan 	if (dst+n > ri->ri_cols)
    408  1.33  macallan 		n = ri->ri_cols - dst;
    409  1.33  macallan 	if (n <= 0)
    410  1.33  macallan 		return;
    411  1.33  macallan 	n *= ri->ri_font->fontwidth;
    412  1.33  macallan 	src *= ri->ri_font->fontwidth;
    413  1.33  macallan 	dst *= ri->ri_font->fontwidth;
    414  1.33  macallan 	row *= ri->ri_font->fontheight;
    415  1.55  macallan 
    416  1.56  macallan 	CG6_WAIT_READY(fbc);
    417  1.56  macallan 
    418  1.33  macallan 	fbc->fbc_alu = CG6_ALU_COPY;
    419  1.55  macallan 	fbc->fbc_mode = GX_BLIT_SRC | GX_MODE_COLOR8;
    420  1.55  macallan 
    421  1.33  macallan 	fbc->fbc_x0 = ri->ri_xorigin + src;
    422  1.33  macallan 	fbc->fbc_y0 = ri->ri_yorigin + row;
    423  1.33  macallan 	fbc->fbc_x1 = ri->ri_xorigin + src + n - 1;
    424  1.33  macallan 	fbc->fbc_y1 = ri->ri_yorigin + row +
    425  1.33  macallan 	    ri->ri_font->fontheight - 1;
    426  1.33  macallan 	fbc->fbc_x2 = ri->ri_xorigin + dst;
    427  1.33  macallan 	fbc->fbc_y2 = ri->ri_yorigin + row;
    428  1.33  macallan 	fbc->fbc_x3 = ri->ri_xorigin + dst + n - 1;
    429  1.33  macallan 	fbc->fbc_y3 = ri->ri_yorigin + row +
    430  1.33  macallan 	    ri->ri_font->fontheight - 1;
    431  1.56  macallan 	CG6_BLIT(fbc);
    432   1.1        pk }
    433   1.1        pk 
    434   1.1        pk static void
    435   1.1        pk cg6_ras_erasecols(void *cookie, int row, int col, int n, long int attr)
    436   1.1        pk {
    437  1.33  macallan 	struct rasops_info *ri = cookie;
    438  1.33  macallan 	struct vcons_screen *scr = ri->ri_hw;
    439  1.33  macallan 	struct cgsix_softc *sc = scr->scr_cookie;
    440  1.33  macallan 	volatile struct cg6_fbc *fbc = sc->sc_fbc;
    441  1.23  macallan 
    442  1.33  macallan 	if ((row < 0) || (row >= ri->ri_rows))
    443  1.33  macallan 		return;
    444  1.33  macallan 	if (col < 0) {
    445  1.33  macallan 		n += col;
    446  1.33  macallan 		col = 0;
    447  1.33  macallan 	}
    448  1.33  macallan 	if (col+n > ri->ri_cols)
    449  1.33  macallan 		n = ri->ri_cols - col;
    450  1.33  macallan 	if (n <= 0)
    451  1.33  macallan 		return;
    452  1.33  macallan 	n *= ri->ri_font->fontwidth;
    453  1.33  macallan 	col *= ri->ri_font->fontwidth;
    454  1.33  macallan 	row *= ri->ri_font->fontheight;
    455  1.55  macallan 
    456  1.56  macallan 	CG6_WAIT_READY(fbc);
    457  1.33  macallan 	fbc->fbc_alu = CG6_ALU_FILL;
    458  1.55  macallan 	fbc->fbc_mode = GX_BLIT_SRC | GX_MODE_COLOR8;
    459  1.55  macallan 
    460  1.33  macallan 	fbc->fbc_fg = ri->ri_devcmap[(attr >> 16) & 0xff];
    461  1.33  macallan 	fbc->fbc_arecty = ri->ri_yorigin + row;
    462  1.33  macallan 	fbc->fbc_arectx = ri->ri_xorigin + col;
    463  1.33  macallan 	fbc->fbc_arecty = ri->ri_yorigin + row +
    464  1.33  macallan 	    ri->ri_font->fontheight - 1;
    465  1.33  macallan 	fbc->fbc_arectx = ri->ri_xorigin + col + n - 1;
    466  1.56  macallan 	CG6_DRAW(fbc);
    467   1.1        pk }
    468   1.1        pk 
    469   1.1        pk static void
    470   1.1        pk cg6_ras_eraserows(void *cookie, int row, int n, long int attr)
    471   1.1        pk {
    472  1.33  macallan 	struct rasops_info *ri = cookie;
    473  1.33  macallan 	struct vcons_screen *scr = ri->ri_hw;
    474  1.33  macallan 	struct cgsix_softc *sc = scr->scr_cookie;
    475  1.33  macallan 	volatile struct cg6_fbc *fbc = sc->sc_fbc;
    476  1.23  macallan 
    477  1.33  macallan 	if (row < 0) {
    478  1.33  macallan 		n += row;
    479  1.33  macallan 		row = 0;
    480  1.33  macallan 	}
    481  1.33  macallan 	if (row+n > ri->ri_rows)
    482  1.33  macallan 		n = ri->ri_rows - row;
    483  1.33  macallan 	if (n <= 0)
    484  1.33  macallan 		return;
    485  1.55  macallan 
    486  1.56  macallan 	CG6_WAIT_READY(fbc);
    487  1.33  macallan 	fbc->fbc_alu = CG6_ALU_FILL;
    488  1.55  macallan 	fbc->fbc_mode = GX_BLIT_SRC | GX_MODE_COLOR8;
    489  1.55  macallan 
    490  1.33  macallan 	fbc->fbc_fg = ri->ri_devcmap[(attr >> 16) & 0xff];
    491  1.33  macallan 	if ((n == ri->ri_rows) && (ri->ri_flg & RI_FULLCLEAR)) {
    492  1.33  macallan 		fbc->fbc_arecty = 0;
    493  1.33  macallan 		fbc->fbc_arectx = 0;
    494  1.33  macallan 		fbc->fbc_arecty = ri->ri_height - 1;
    495  1.33  macallan 		fbc->fbc_arectx = ri->ri_width - 1;
    496  1.33  macallan 	} else {
    497  1.33  macallan 		row *= ri->ri_font->fontheight;
    498  1.33  macallan 		fbc->fbc_arecty = ri->ri_yorigin + row;
    499  1.33  macallan 		fbc->fbc_arectx = ri->ri_xorigin;
    500  1.33  macallan 		fbc->fbc_arecty = ri->ri_yorigin + row +
    501  1.33  macallan 		    (n * ri->ri_font->fontheight) - 1;
    502  1.33  macallan 		fbc->fbc_arectx = ri->ri_xorigin + ri->ri_emuwidth - 1;
    503  1.23  macallan 	}
    504  1.56  macallan 	CG6_DRAW(fbc);
    505   1.1        pk }
    506   1.1        pk 
    507   1.1        pk void
    508  1.25   tsutsui cg6attach(struct cgsix_softc *sc, const char *name, int isconsole)
    509   1.1        pk {
    510   1.1        pk 	struct fbdevice *fb = &sc->sc_fb;
    511  1.18    martin 	struct wsemuldisplaydev_attach_args aa;
    512  1.33  macallan 	struct rasops_info *ri = &cg6_console_screen.scr_ri;
    513  1.18    martin 	unsigned long defattr;
    514  1.33  macallan 
    515   1.1        pk 	fb->fb_driver = &cg6_fbdriver;
    516   1.1        pk 
    517   1.1        pk 	/* Don't have to map the pfour register on the cgsix. */
    518   1.1        pk 	fb->fb_pfour = NULL;
    519   1.1        pk 
    520   1.1        pk 	fb->fb_type.fb_cmsize = 256;
    521  1.23  macallan 	fb->fb_type.fb_size = sc->sc_ramsize;
    522  1.54  macallan 
    523   1.1        pk 	printf(": %s, %d x %d", name,
    524   1.1        pk 	       fb->fb_type.fb_width, fb->fb_type.fb_height);
    525  1.18    martin 	if(sc->sc_fhc) {
    526  1.23  macallan 		sc->sc_fhcrev = (*sc->sc_fhc >> FHC_REV_SHIFT) &
    527   1.1        pk 			(FHC_REV_MASK >> FHC_REV_SHIFT);
    528  1.18    martin 	} else
    529  1.18    martin 		sc->sc_fhcrev=-1;
    530   1.1        pk 	printf(", rev %d", sc->sc_fhcrev);
    531   1.1        pk 
    532   1.1        pk 	/* reset cursor & frame buffer controls */
    533   1.1        pk 	cg6_reset(sc);
    534   1.1        pk 
    535   1.1        pk 	/* enable video */
    536   1.1        pk 	sc->sc_thc->thc_misc |= THC_MISC_VIDEN;
    537   1.1        pk 
    538   1.1        pk 	if (isconsole) {
    539   1.1        pk 		printf(" (console)");
    540   1.1        pk 	}
    541  1.26   thorpej 	printf("\n");
    542   1.1        pk 
    543  1.18    martin 	fb_attach(&sc->sc_fb, isconsole);
    544  1.23  macallan 	sc->sc_width = fb->fb_type.fb_width;
    545  1.23  macallan 	sc->sc_stride = fb->fb_type.fb_width;
    546  1.23  macallan 	sc->sc_height = fb->fb_type.fb_height;
    547  1.60  macallan 
    548  1.39  macallan 	printf("%s: framebuffer size: %d MB\n", device_xname(sc->sc_dev),
    549  1.24  macallan 	    sc->sc_ramsize >> 20);
    550  1.24  macallan 
    551  1.20    martin 	/* setup rasops and so on for wsdisplay */
    552  1.41  macallan 	memcpy(sc->sc_default_cmap, rasops_cmap, 768);
    553  1.18    martin 	wsfont_init();
    554  1.18    martin 	cg6_ras_init(sc);
    555  1.23  macallan 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    556  1.23  macallan 	sc->sc_bg = WS_DEFAULT_BG;
    557  1.52  macallan 	sc->sc_fb_is_open = FALSE;
    558  1.23  macallan 
    559  1.33  macallan 	vcons_init(&sc->vd, sc, &cgsix_defaultscreen, &cgsix_accessops);
    560  1.33  macallan 	sc->vd.init_screen = cgsix_init_screen;
    561  1.23  macallan 
    562  1.57  macallan 	sc->sc_gc.gc_bitblt = cgsix_bitblt;
    563  1.57  macallan 	sc->sc_gc.gc_blitcookie = sc;
    564  1.57  macallan 	sc->sc_gc.gc_rop = CG6_ALU_COPY;
    565  1.68  macallan 	sc->vd.show_screen_cookie = &sc->sc_gc;
    566  1.68  macallan 	sc->vd.show_screen_cb = glyphcache_adapt;
    567  1.57  macallan 
    568  1.27  macallan 	if(isconsole) {
    569  1.27  macallan 		/* we mess with cg6_console_screen only once */
    570  1.33  macallan 		vcons_init_screen(&sc->vd, &cg6_console_screen, 1,
    571  1.33  macallan 		    &defattr);
    572  1.63  macallan 		sc->sc_bg = (defattr >> 16) & 0xf; /* yes, this is an index into devcmap */
    573  1.63  macallan 
    574  1.63  macallan 		/*
    575  1.63  macallan 		 * XXX
    576  1.63  macallan 		 * Is this actually necessary? We're going to use the blitter later on anyway.
    577  1.63  macallan 		 */
    578  1.63  macallan 		/* We need unaccelerated initial screen clear on old revisions */
    579  1.63  macallan 		if (sc->sc_fhcrev < 2) {
    580  1.63  macallan 			memset(sc->sc_fb.fb_pixels, ri->ri_devcmap[sc->sc_bg],
    581  1.63  macallan 			    sc->sc_stride * sc->sc_height);
    582  1.63  macallan 		} else
    583  1.63  macallan 			cgsix_clearscreen(sc);
    584  1.63  macallan 
    585  1.33  macallan 		cg6_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    586  1.33  macallan 
    587  1.27  macallan 		cgsix_defaultscreen.textops = &ri->ri_ops;
    588  1.27  macallan 		cgsix_defaultscreen.capabilities = ri->ri_caps;
    589  1.27  macallan 		cgsix_defaultscreen.nrows = ri->ri_rows;
    590  1.27  macallan 		cgsix_defaultscreen.ncols = ri->ri_cols;
    591  1.33  macallan 		SCREEN_VISIBLE(&cg6_console_screen);
    592  1.33  macallan 		sc->vd.active = &cg6_console_screen;
    593  1.45  macallan 		wsdisplay_cnattach(&cgsix_defaultscreen, ri, 0, 0, defattr);
    594  1.60  macallan 		if (ri->ri_flg & RI_ENABLE_ALPHA) {
    595  1.60  macallan 			glyphcache_init(&sc->sc_gc, sc->sc_height + 5,
    596  1.57  macallan 				(sc->sc_ramsize / sc->sc_stride) -
    597  1.57  macallan 				  sc->sc_height - 5,
    598  1.57  macallan 				sc->sc_width,
    599  1.57  macallan 				ri->ri_font->fontwidth,
    600  1.57  macallan 				ri->ri_font->fontheight,
    601  1.57  macallan 				defattr);
    602  1.60  macallan 		}
    603  1.45  macallan 		vcons_replay_msgbuf(&cg6_console_screen);
    604  1.27  macallan 	} else {
    605  1.57  macallan 		/*
    606  1.57  macallan 		 * since we're not the console we can postpone the rest
    607  1.57  macallan 		 * until someone actually allocates a screen for us
    608  1.27  macallan 		 */
    609  1.57  macallan 		if (cg6_console_screen.scr_ri.ri_rows == 0) {
    610  1.57  macallan 			/* do some minimal setup to avoid weirdnesses later */
    611  1.57  macallan 			vcons_init_screen(&sc->vd, &cg6_console_screen, 1,
    612  1.57  macallan 			    &defattr);
    613  1.61  macallan 		} else
    614  1.61  macallan 			(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    615  1.63  macallan 		sc->sc_bg = (defattr >> 16) & 0xf;
    616  1.60  macallan 		if (ri->ri_flg & RI_ENABLE_ALPHA) {
    617  1.60  macallan 			glyphcache_init(&sc->sc_gc, sc->sc_height + 5,
    618  1.57  macallan 				(sc->sc_ramsize / sc->sc_stride) -
    619  1.57  macallan 				  sc->sc_height - 5,
    620  1.57  macallan 				sc->sc_width,
    621  1.57  macallan 				ri->ri_font->fontwidth,
    622  1.57  macallan 				ri->ri_font->fontheight,
    623  1.57  macallan 				defattr);
    624  1.60  macallan 		}
    625  1.27  macallan 	}
    626  1.57  macallan 	cg6_setup_palette(sc);
    627  1.27  macallan 
    628  1.27  macallan 	aa.scrdata = &cgsix_screenlist;
    629  1.18    martin 	aa.console = isconsole;
    630  1.18    martin 	aa.accessops = &cgsix_accessops;
    631  1.33  macallan 	aa.accesscookie = &sc->vd;
    632  1.39  macallan 	config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
    633   1.1        pk }
    634   1.1        pk 
    635   1.1        pk 
    636   1.1        pk int
    637  1.28  christos cgsixopen(dev_t dev, int flags, int mode, struct lwp *l)
    638   1.1        pk {
    639  1.52  macallan 	device_t dv = device_lookup(&cgsix_cd, minor(dev));
    640  1.52  macallan 	struct cgsix_softc *sc = device_private(dv);
    641   1.1        pk 
    642  1.52  macallan 	if (dv == NULL)
    643  1.22    martin 		return ENXIO;
    644  1.52  macallan 	sc->sc_fb_is_open = TRUE;
    645  1.52  macallan 
    646  1.22    martin 	return 0;
    647   1.1        pk }
    648   1.1        pk 
    649   1.1        pk int
    650  1.28  christos cgsixclose(dev_t dev, int flags, int mode, struct lwp *l)
    651   1.1        pk {
    652  1.39  macallan 	device_t dv = device_lookup(&cgsix_cd, minor(dev));
    653  1.39  macallan 	struct cgsix_softc *sc = device_private(dv);
    654   1.1        pk 
    655   1.1        pk 	cg6_reset(sc);
    656  1.52  macallan 	sc->sc_fb_is_open = FALSE;
    657   1.1        pk 
    658  1.52  macallan 	if (IS_IN_EMUL_MODE(sc)) {
    659  1.52  macallan 		struct vcons_screen *ms = sc->vd.active;
    660  1.52  macallan 
    661  1.52  macallan 		cg6_ras_init(sc);
    662  1.52  macallan 		cg6_setup_palette(sc);
    663  1.59  macallan 		glyphcache_wipe(&sc->sc_gc);
    664  1.52  macallan 
    665  1.52  macallan 		/* we don't know if the screen exists */
    666  1.52  macallan 		if (ms != NULL)
    667  1.52  macallan 			vcons_redraw_screen(ms);
    668  1.52  macallan 	}
    669  1.22    martin 	return 0;
    670   1.1        pk }
    671   1.1        pk 
    672   1.1        pk int
    673  1.34  christos cgsixioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
    674   1.1        pk {
    675  1.38  drochner 	struct cgsix_softc *sc = device_lookup_private(&cgsix_cd, minor(dev));
    676  1.16       chs 	union cursor_cmap tcm;
    677  1.16       chs 	uint32_t image[32], mask[32];
    678   1.1        pk 	u_int count;
    679   1.1        pk 	int v, error;
    680   1.1        pk 
    681  1.18    martin #ifdef CGSIX_DEBUG
    682  1.52  macallan 	printf("cgsixioctl(%lx)\n",cmd);
    683  1.18    martin #endif
    684  1.18    martin 
    685   1.1        pk 	switch (cmd) {
    686   1.1        pk 
    687   1.1        pk 	case FBIOGTYPE:
    688   1.1        pk 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    689   1.1        pk 		break;
    690   1.1        pk 
    691   1.1        pk 	case FBIOGATTR:
    692   1.1        pk #define fba ((struct fbgattr *)data)
    693   1.1        pk 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    694   1.1        pk 		fba->owner = 0;		/* XXX ??? */
    695   1.1        pk 		fba->fbtype = sc->sc_fb.fb_type;
    696   1.1        pk 		fba->sattr.flags = 0;
    697   1.1        pk 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    698   1.1        pk 		fba->sattr.dev_specific[0] = -1;
    699   1.1        pk 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    700   1.1        pk 		fba->emu_types[1] = -1;
    701   1.1        pk #undef fba
    702   1.1        pk 		break;
    703   1.1        pk 
    704   1.1        pk 	case FBIOGETCMAP:
    705   1.1        pk #define	p ((struct fbcmap *)data)
    706   1.1        pk 		return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
    707   1.1        pk 
    708   1.1        pk 	case FBIOPUTCMAP:
    709   1.1        pk 		/* copy to software map */
    710   1.1        pk 		error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
    711   1.1        pk 		if (error)
    712  1.22    martin 			return error;
    713   1.1        pk 		/* now blast them into the chip */
    714   1.1        pk 		/* XXX should use retrace interrupt */
    715   1.1        pk 		cg6_loadcmap(sc, p->index, p->count);
    716   1.1        pk #undef p
    717   1.1        pk 		break;
    718   1.1        pk 
    719   1.1        pk 	case FBIOGVIDEO:
    720   1.1        pk 		*(int *)data = sc->sc_blanked;
    721   1.1        pk 		break;
    722   1.1        pk 
    723   1.1        pk 	case FBIOSVIDEO:
    724  1.33  macallan 		cg6_blank(sc, !(*(int *)data));
    725   1.1        pk 		break;
    726   1.1        pk 
    727   1.1        pk /* these are for both FBIOSCURSOR and FBIOGCURSOR */
    728   1.1        pk #define p ((struct fbcursor *)data)
    729   1.1        pk #define cc (&sc->sc_cursor)
    730   1.1        pk 
    731   1.1        pk 	case FBIOGCURSOR:
    732   1.1        pk 		/* do not quite want everything here... */
    733   1.1        pk 		p->set = FB_CUR_SETALL;	/* close enough, anyway */
    734   1.1        pk 		p->enable = cc->cc_enable;
    735   1.1        pk 		p->pos = cc->cc_pos;
    736   1.1        pk 		p->hot = cc->cc_hot;
    737   1.1        pk 		p->size = cc->cc_size;
    738   1.1        pk 
    739   1.1        pk 		/* begin ugh ... can we lose some of this crap?? */
    740   1.1        pk 		if (p->image != NULL) {
    741   1.1        pk 			count = cc->cc_size.y * 32 / NBBY;
    742  1.16       chs 			error = copyout(cc->cc_bits[1], p->image, count);
    743   1.1        pk 			if (error)
    744  1.22    martin 				return error;
    745  1.16       chs 			error = copyout(cc->cc_bits[0], p->mask, count);
    746   1.1        pk 			if (error)
    747  1.22    martin 				return error;
    748   1.1        pk 		}
    749   1.1        pk 		if (p->cmap.red != NULL) {
    750   1.1        pk 			error = bt_getcmap(&p->cmap,
    751   1.1        pk 			    (union bt_cmap *)&cc->cc_color, 2, 1);
    752   1.1        pk 			if (error)
    753  1.22    martin 				return error;
    754   1.1        pk 		} else {
    755   1.1        pk 			p->cmap.index = 0;
    756   1.1        pk 			p->cmap.count = 2;
    757   1.1        pk 		}
    758   1.1        pk 		/* end ugh */
    759   1.1        pk 		break;
    760   1.1        pk 
    761   1.1        pk 	case FBIOSCURSOR:
    762   1.1        pk 		/*
    763   1.1        pk 		 * For setcmap and setshape, verify parameters, so that
    764   1.1        pk 		 * we do not get halfway through an update and then crap
    765   1.1        pk 		 * out with the software state screwed up.
    766   1.1        pk 		 */
    767   1.1        pk 		v = p->set;
    768   1.1        pk 		if (v & FB_CUR_SETCMAP) {
    769   1.1        pk 			/*
    770   1.1        pk 			 * This use of a temporary copy of the cursor
    771   1.1        pk 			 * colormap is not terribly efficient, but these
    772   1.1        pk 			 * copies are small (8 bytes)...
    773   1.1        pk 			 */
    774   1.1        pk 			tcm = cc->cc_color;
    775  1.23  macallan 			error = bt_putcmap(&p->cmap, (union bt_cmap *)&tcm, 2,
    776  1.23  macallan 			    1);
    777   1.1        pk 			if (error)
    778  1.22    martin 				return error;
    779   1.1        pk 		}
    780   1.1        pk 		if (v & FB_CUR_SETSHAPE) {
    781   1.1        pk 			if ((u_int)p->size.x > 32 || (u_int)p->size.y > 32)
    782  1.22    martin 				return EINVAL;
    783   1.1        pk 			count = p->size.y * 32 / NBBY;
    784  1.16       chs 			error = copyin(p->image, image, count);
    785  1.16       chs 			if (error)
    786  1.16       chs 				return error;
    787  1.16       chs 			error = copyin(p->mask, mask, count);
    788  1.16       chs 			if (error)
    789  1.16       chs 				return error;
    790   1.1        pk 		}
    791   1.1        pk 
    792   1.1        pk 		/* parameters are OK; do it */
    793   1.1        pk 		if (v & (FB_CUR_SETCUR | FB_CUR_SETPOS | FB_CUR_SETHOT)) {
    794   1.1        pk 			if (v & FB_CUR_SETCUR)
    795   1.1        pk 				cc->cc_enable = p->enable;
    796   1.1        pk 			if (v & FB_CUR_SETPOS)
    797   1.1        pk 				cc->cc_pos = p->pos;
    798   1.1        pk 			if (v & FB_CUR_SETHOT)
    799   1.1        pk 				cc->cc_hot = p->hot;
    800   1.1        pk 			cg6_setcursor(sc);
    801   1.1        pk 		}
    802   1.1        pk 		if (v & FB_CUR_SETCMAP) {
    803   1.1        pk 			cc->cc_color = tcm;
    804   1.1        pk 			cg6_loadomap(sc); /* XXX defer to vertical retrace */
    805   1.1        pk 		}
    806   1.1        pk 		if (v & FB_CUR_SETSHAPE) {
    807   1.1        pk 			cc->cc_size = p->size;
    808   1.1        pk 			count = p->size.y * 32 / NBBY;
    809  1.16       chs 			memset(cc->cc_bits, 0, sizeof cc->cc_bits);
    810  1.16       chs 			memcpy(cc->cc_bits[1], image, count);
    811  1.16       chs 			memcpy(cc->cc_bits[0], mask, count);
    812   1.1        pk 			cg6_loadcursor(sc);
    813   1.1        pk 		}
    814   1.1        pk 		break;
    815   1.1        pk 
    816   1.1        pk #undef p
    817   1.1        pk #undef cc
    818   1.1        pk 
    819   1.1        pk 	case FBIOGCURPOS:
    820   1.1        pk 		*(struct fbcurpos *)data = sc->sc_cursor.cc_pos;
    821   1.1        pk 		break;
    822   1.1        pk 
    823   1.1        pk 	case FBIOSCURPOS:
    824   1.1        pk 		sc->sc_cursor.cc_pos = *(struct fbcurpos *)data;
    825   1.1        pk 		cg6_setcursor(sc);
    826   1.1        pk 		break;
    827   1.1        pk 
    828   1.1        pk 	case FBIOGCURMAX:
    829   1.1        pk 		/* max cursor size is 32x32 */
    830   1.1        pk 		((struct fbcurpos *)data)->x = 32;
    831   1.1        pk 		((struct fbcurpos *)data)->y = 32;
    832   1.1        pk 		break;
    833   1.1        pk 
    834   1.1        pk 	default:
    835   1.1        pk #ifdef DEBUG
    836   1.1        pk 		log(LOG_NOTICE, "cgsixioctl(0x%lx) (%s[%d])\n", cmd,
    837  1.29  christos 		    l->l_proc->p_comm, l->l_proc->p_pid);
    838   1.1        pk #endif
    839  1.22    martin 		return ENOTTY;
    840   1.1        pk 	}
    841  1.22    martin 	return 0;
    842   1.1        pk }
    843   1.1        pk 
    844   1.1        pk /*
    845   1.1        pk  * Clean up hardware state (e.g., after bootup or after X crashes).
    846   1.1        pk  */
    847   1.1        pk static void
    848  1.22    martin cg6_reset(struct cgsix_softc *sc)
    849   1.1        pk {
    850   1.1        pk 	volatile struct cg6_tec_xxx *tec;
    851   1.1        pk 	int fhc;
    852   1.1        pk 	volatile struct bt_regs *bt;
    853   1.1        pk 
    854   1.1        pk 	/* hide the cursor, just in case */
    855   1.1        pk 	sc->sc_thc->thc_cursxy = (THC_CURSOFF << 16) | THC_CURSOFF;
    856   1.1        pk 
    857   1.1        pk 	/* turn off frobs in transform engine (makes X11 work) */
    858   1.1        pk 	tec = sc->sc_tec;
    859   1.1        pk 	tec->tec_mv = 0;
    860   1.1        pk 	tec->tec_clip = 0;
    861   1.1        pk 	tec->tec_vdc = 0;
    862   1.1        pk 
    863   1.1        pk 	/* take care of hardware bugs in old revisions */
    864   1.1        pk 	if (sc->sc_fhcrev < 5) {
    865   1.1        pk 		/*
    866  1.17       wiz 		 * Keep current resolution; set CPU to 68020, set test
    867   1.1        pk 		 * window (size 1Kx1K), and for rev 1, disable dest cache.
    868   1.1        pk 		 */
    869   1.1        pk 		fhc = (*sc->sc_fhc & FHC_RES_MASK) | FHC_CPU_68020 |
    870   1.1        pk 		    FHC_TEST |
    871   1.1        pk 		    (11 << FHC_TESTX_SHIFT) | (11 << FHC_TESTY_SHIFT);
    872   1.1        pk 		if (sc->sc_fhcrev < 2)
    873   1.1        pk 			fhc |= FHC_DST_DISABLE;
    874   1.1        pk 		*sc->sc_fhc = fhc;
    875   1.1        pk 	}
    876   1.1        pk 
    877   1.1        pk 	/* Enable cursor in Brooktree DAC. */
    878   1.1        pk 	bt = sc->sc_bt;
    879   1.1        pk 	bt->bt_addr = 0x06 << 24;
    880   1.1        pk 	bt->bt_ctrl |= 0x03 << 24;
    881   1.1        pk }
    882   1.1        pk 
    883   1.1        pk static void
    884  1.22    martin cg6_setcursor(struct cgsix_softc *sc)
    885   1.1        pk {
    886   1.1        pk 
    887   1.1        pk 	/* we need to subtract the hot-spot value here */
    888   1.1        pk #define COORD(f) (sc->sc_cursor.cc_pos.f - sc->sc_cursor.cc_hot.f)
    889   1.1        pk 	sc->sc_thc->thc_cursxy = sc->sc_cursor.cc_enable ?
    890   1.1        pk 	    ((COORD(x) << 16) | (COORD(y) & 0xffff)) :
    891   1.1        pk 	    (THC_CURSOFF << 16) | THC_CURSOFF;
    892   1.1        pk #undef COORD
    893   1.1        pk }
    894   1.1        pk 
    895   1.1        pk static void
    896  1.22    martin cg6_loadcursor(struct cgsix_softc *sc)
    897   1.1        pk {
    898   1.1        pk 	volatile struct cg6_thc *thc;
    899   1.1        pk 	u_int edgemask, m;
    900   1.1        pk 	int i;
    901   1.1        pk 
    902   1.1        pk 	/*
    903   1.1        pk 	 * Keep the top size.x bits.  Here we *throw out* the top
    904   1.1        pk 	 * size.x bits from an all-one-bits word, introducing zeros in
    905   1.1        pk 	 * the top size.x bits, then invert all the bits to get what
    906   1.1        pk 	 * we really wanted as our mask.  But this fails if size.x is
    907   1.1        pk 	 * 32---a sparc uses only the low 5 bits of the shift count---
    908   1.1        pk 	 * so we have to special case that.
    909   1.1        pk 	 */
    910   1.1        pk 	edgemask = ~0;
    911   1.1        pk 	if (sc->sc_cursor.cc_size.x < 32)
    912   1.1        pk 		edgemask = ~(edgemask >> sc->sc_cursor.cc_size.x);
    913   1.1        pk 	thc = sc->sc_thc;
    914   1.1        pk 	for (i = 0; i < 32; i++) {
    915   1.1        pk 		m = sc->sc_cursor.cc_bits[0][i] & edgemask;
    916   1.1        pk 		thc->thc_cursmask[i] = m;
    917   1.1        pk 		thc->thc_cursbits[i] = m & sc->sc_cursor.cc_bits[1][i];
    918   1.1        pk 	}
    919   1.1        pk }
    920   1.1        pk 
    921   1.1        pk /*
    922   1.1        pk  * Load a subset of the current (new) colormap into the color DAC.
    923   1.1        pk  */
    924   1.1        pk static void
    925  1.22    martin cg6_loadcmap(struct cgsix_softc *sc, int start, int ncolors)
    926   1.1        pk {
    927   1.1        pk 	volatile struct bt_regs *bt;
    928   1.1        pk 	u_int *ip, i;
    929   1.1        pk 	int count;
    930   1.1        pk 
    931   1.1        pk 	ip = &sc->sc_cmap.cm_chip[BT_D4M3(start)];	/* start/4 * 3 */
    932   1.1        pk 	count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
    933   1.1        pk 	bt = sc->sc_bt;
    934   1.1        pk 	bt->bt_addr = BT_D4M4(start) << 24;
    935   1.1        pk 	while (--count >= 0) {
    936   1.1        pk 		i = *ip++;
    937   1.1        pk 		/* hardware that makes one want to pound boards with hammers */
    938   1.1        pk 		bt->bt_cmap = i;
    939   1.1        pk 		bt->bt_cmap = i << 8;
    940   1.1        pk 		bt->bt_cmap = i << 16;
    941   1.1        pk 		bt->bt_cmap = i << 24;
    942   1.1        pk 	}
    943   1.1        pk }
    944   1.1        pk 
    945   1.1        pk /*
    946   1.1        pk  * Load the cursor (overlay `foreground' and `background') colors.
    947   1.1        pk  */
    948   1.1        pk static void
    949  1.22    martin cg6_loadomap(struct cgsix_softc *sc)
    950   1.1        pk {
    951   1.1        pk 	volatile struct bt_regs *bt;
    952   1.1        pk 	u_int i;
    953   1.1        pk 
    954   1.1        pk 	bt = sc->sc_bt;
    955   1.1        pk 	bt->bt_addr = 0x01 << 24;	/* set background color */
    956   1.1        pk 	i = sc->sc_cursor.cc_color.cm_chip[0];
    957   1.1        pk 	bt->bt_omap = i;		/* R */
    958   1.1        pk 	bt->bt_omap = i << 8;		/* G */
    959   1.1        pk 	bt->bt_omap = i << 16;		/* B */
    960   1.1        pk 
    961   1.1        pk 	bt->bt_addr = 0x03 << 24;	/* set foreground color */
    962   1.1        pk 	bt->bt_omap = i << 24;		/* R */
    963   1.1        pk 	i = sc->sc_cursor.cc_color.cm_chip[1];
    964   1.1        pk 	bt->bt_omap = i;		/* G */
    965   1.1        pk 	bt->bt_omap = i << 8;		/* B */
    966   1.1        pk }
    967   1.1        pk 
    968  1.33  macallan /* blank or unblank the screen */
    969  1.33  macallan static void
    970  1.33  macallan cg6_blank(struct cgsix_softc *sc, int flag)
    971  1.33  macallan {
    972  1.33  macallan 
    973  1.33  macallan 	if (sc->sc_blanked != flag) {
    974  1.33  macallan 		sc->sc_blanked = flag;
    975  1.33  macallan 		if (flag) {
    976  1.33  macallan 			sc->sc_thc->thc_misc &= ~THC_MISC_VIDEN;
    977  1.33  macallan 		} else {
    978  1.33  macallan 			sc->sc_thc->thc_misc |= THC_MISC_VIDEN;
    979  1.33  macallan 		}
    980  1.33  macallan 	}
    981  1.33  macallan }
    982  1.33  macallan 
    983  1.33  macallan /*
    984  1.33  macallan  * this is called on panic or ddb entry - force the console to the front, reset
    985  1.33  macallan  * the colour map and enable drawing so we actually see the message even when X
    986  1.33  macallan  * is running
    987  1.33  macallan  */
    988   1.1        pk static void
    989  1.39  macallan cg6_unblank(device_t dev)
    990   1.1        pk {
    991  1.38  drochner 	struct cgsix_softc *sc = device_private(dev);
    992   1.1        pk 
    993  1.33  macallan 	cg6_blank(sc, 0);
    994   1.1        pk }
    995   1.1        pk 
    996   1.1        pk /* XXX the following should be moved to a "user interface" header */
    997   1.1        pk /*
    998   1.1        pk  * Base addresses at which users can mmap() the various pieces of a cg6.
    999   1.1        pk  * Note that although the Brooktree color registers do not occupy 8K,
   1000   1.1        pk  * the X server dies if we do not allow it to map 8K there (it just maps
   1001   1.1        pk  * from 0x70000000 forwards, as a contiguous chunk).
   1002   1.1        pk  */
   1003   1.1        pk #define	CG6_USER_FBC	0x70000000
   1004   1.1        pk #define	CG6_USER_TEC	0x70001000
   1005   1.1        pk #define	CG6_USER_BTREGS	0x70002000
   1006   1.1        pk #define	CG6_USER_FHC	0x70004000
   1007   1.1        pk #define	CG6_USER_THC	0x70005000
   1008   1.1        pk #define	CG6_USER_ROM	0x70006000
   1009   1.1        pk #define	CG6_USER_RAM	0x70016000
   1010   1.1        pk #define	CG6_USER_DHC	0x80000000
   1011   1.1        pk 
   1012   1.1        pk struct mmo {
   1013   1.2       eeh 	u_long	mo_uaddr;	/* user (virtual) address */
   1014   1.2       eeh 	u_long	mo_size;	/* size, or 0 for video ram size */
   1015   1.2       eeh 	u_long	mo_physoff;	/* offset from sc_physadr */
   1016   1.1        pk };
   1017   1.1        pk 
   1018   1.1        pk /*
   1019   1.1        pk  * Return the address that would map the given device at the given
   1020   1.1        pk  * offset, allowing for the given protection, or return -1 for error.
   1021   1.1        pk  *
   1022   1.1        pk  * XXX	needs testing against `demanding' applications (e.g., aviator)
   1023   1.1        pk  */
   1024   1.1        pk paddr_t
   1025  1.22    martin cgsixmmap(dev_t dev, off_t off, int prot)
   1026   1.1        pk {
   1027  1.38  drochner 	struct cgsix_softc *sc = device_lookup_private(&cgsix_cd, minor(dev));
   1028   1.1        pk 	struct mmo *mo;
   1029  1.68  macallan 	u_int u, sz, flags;
   1030   1.1        pk 	static struct mmo mmo[] = {
   1031   1.1        pk 		{ CG6_USER_RAM, 0, CGSIX_RAM_OFFSET },
   1032   1.1        pk 
   1033   1.1        pk 		/* do not actually know how big most of these are! */
   1034   1.1        pk 		{ CG6_USER_FBC, 1, CGSIX_FBC_OFFSET },
   1035   1.1        pk 		{ CG6_USER_TEC, 1, CGSIX_TEC_OFFSET },
   1036   1.1        pk 		{ CG6_USER_BTREGS, 8192 /* XXX */, CGSIX_BT_OFFSET },
   1037   1.1        pk 		{ CG6_USER_FHC, 1, CGSIX_FHC_OFFSET },
   1038   1.1        pk 		{ CG6_USER_THC, sizeof(struct cg6_thc), CGSIX_THC_OFFSET },
   1039   1.1        pk 		{ CG6_USER_ROM, 65536, CGSIX_ROM_OFFSET },
   1040   1.1        pk 		{ CG6_USER_DHC, 1, CGSIX_DHC_OFFSET },
   1041   1.1        pk 	};
   1042   1.1        pk #define NMMO (sizeof mmo / sizeof *mmo)
   1043   1.1        pk 
   1044   1.1        pk 	if (off & PGOFSET)
   1045   1.1        pk 		panic("cgsixmmap");
   1046   1.1        pk 
   1047   1.1        pk 	/*
   1048   1.1        pk 	 * Entries with size 0 map video RAM (i.e., the size in fb data).
   1049   1.1        pk 	 *
   1050   1.1        pk 	 * Since we work in pages, the fact that the map offset table's
   1051   1.1        pk 	 * sizes are sometimes bizarre (e.g., 1) is effectively ignored:
   1052   1.1        pk 	 * one byte is as good as one page.
   1053   1.1        pk 	 */
   1054   1.1        pk 	for (mo = mmo; mo < &mmo[NMMO]; mo++) {
   1055   1.2       eeh 		if ((u_long)off < mo->mo_uaddr)
   1056   1.1        pk 			continue;
   1057   1.1        pk 		u = off - mo->mo_uaddr;
   1058  1.68  macallan 		if (mo->mo_size == 0) {
   1059  1.68  macallan 			flags = BUS_SPACE_MAP_LINEAR |
   1060  1.68  macallan 				BUS_SPACE_MAP_PREFETCHABLE;
   1061  1.68  macallan 			sz = sc->sc_ramsize;
   1062  1.68  macallan 		} else {
   1063  1.68  macallan 			flags = BUS_SPACE_MAP_LINEAR;
   1064  1.68  macallan 			sz = mo->mo_size;
   1065  1.68  macallan 		}
   1066   1.1        pk 		if (u < sz) {
   1067   1.6       eeh 			return (bus_space_mmap(sc->sc_bustag,
   1068   1.6       eeh 				sc->sc_paddr, u+mo->mo_physoff,
   1069  1.68  macallan 				prot, flags));
   1070   1.1        pk 		}
   1071   1.1        pk 	}
   1072   1.1        pk 
   1073   1.1        pk #ifdef DEBUG
   1074   1.1        pk 	{
   1075  1.10   thorpej 	  struct proc *p = curlwp->l_proc;	/* XXX */
   1076   1.4       chs 	  log(LOG_NOTICE, "cgsixmmap(0x%llx) (%s[%d])\n",
   1077   1.4       chs 		(long long)off, p->p_comm, p->p_pid);
   1078   1.1        pk 	}
   1079   1.1        pk #endif
   1080  1.22    martin 	return -1;	/* not a user-map offset */
   1081   1.1        pk }
   1082  1.18    martin 
   1083  1.23  macallan static void
   1084  1.23  macallan cg6_setup_palette(struct cgsix_softc *sc)
   1085  1.18    martin {
   1086  1.23  macallan 	int i, j;
   1087  1.39  macallan 
   1088  1.57  macallan 	rasops_get_cmap(&cg6_console_screen.scr_ri, sc->sc_default_cmap,
   1089  1.57  macallan 	    sizeof(sc->sc_default_cmap));
   1090  1.23  macallan 	j = 0;
   1091  1.23  macallan 	for (i = 0; i < 256; i++) {
   1092  1.39  macallan 		sc->sc_cmap.cm_map[i][0] = sc->sc_default_cmap[j];
   1093  1.23  macallan 		j++;
   1094  1.39  macallan 		sc->sc_cmap.cm_map[i][1] = sc->sc_default_cmap[j];
   1095  1.23  macallan 		j++;
   1096  1.39  macallan 		sc->sc_cmap.cm_map[i][2] = sc->sc_default_cmap[j];
   1097  1.23  macallan 		j++;
   1098  1.23  macallan 	}
   1099  1.23  macallan 	cg6_loadcmap(sc, 0, 256);
   1100  1.18    martin }
   1101  1.18    martin 
   1102  1.18    martin int
   1103  1.34  christos cgsix_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
   1104  1.30      jmmv 	struct lwp *l)
   1105  1.18    martin {
   1106  1.18    martin 	/* we'll probably need to add more stuff here */
   1107  1.33  macallan 	struct vcons_data *vd = v;
   1108  1.33  macallan 	struct cgsix_softc *sc = vd->cookie;
   1109  1.18    martin 	struct wsdisplay_fbinfo *wdf;
   1110  1.33  macallan 	struct vcons_screen *ms = sc->vd.active;
   1111  1.54  macallan 
   1112  1.18    martin #ifdef CGSIX_DEBUG
   1113  1.52  macallan 	printf("cgsix_ioctl(%lx)\n",cmd);
   1114  1.18    martin #endif
   1115  1.18    martin 	switch (cmd) {
   1116  1.18    martin 		case WSDISPLAYIO_GTYPE:
   1117  1.18    martin 			*(u_int *)data = WSDISPLAY_TYPE_SUNTCX;
   1118  1.18    martin 			return 0;
   1119  1.18    martin 		case WSDISPLAYIO_GINFO:
   1120  1.18    martin 			wdf = (void *)data;
   1121  1.66  macallan 			wdf->height = sc->sc_height;
   1122  1.66  macallan 			wdf->width = sc->sc_width;
   1123  1.66  macallan 			wdf->depth = 8;
   1124  1.18    martin 			wdf->cmsize = 256;
   1125  1.18    martin 			return 0;
   1126  1.19     perry 
   1127  1.18    martin 		case WSDISPLAYIO_GETCMAP:
   1128  1.22    martin 			return cgsix_getcmap(sc,
   1129  1.22    martin 			    (struct wsdisplay_cmap *)data);
   1130  1.18    martin 		case WSDISPLAYIO_PUTCMAP:
   1131  1.22    martin 			return cgsix_putcmap(sc,
   1132  1.22    martin 			    (struct wsdisplay_cmap *)data);
   1133  1.19     perry 
   1134  1.50       mrg 		case WSDISPLAYIO_LINEBYTES:
   1135  1.50       mrg 			*(u_int *)data = sc->sc_stride;
   1136  1.50       mrg 			return 0;
   1137  1.50       mrg 
   1138  1.18    martin 		case WSDISPLAYIO_SMODE:
   1139  1.18    martin 			{
   1140  1.23  macallan 				int new_mode = *(int*)data;
   1141  1.52  macallan 
   1142  1.52  macallan 				if (new_mode != sc->sc_mode) {
   1143  1.23  macallan 					sc->sc_mode = new_mode;
   1144  1.52  macallan 					if (IS_IN_EMUL_MODE(sc)) {
   1145  1.23  macallan 						cg6_reset(sc);
   1146  1.23  macallan 						cg6_ras_init(sc);
   1147  1.33  macallan 						cg6_setup_palette(sc);
   1148  1.59  macallan 						glyphcache_wipe(&sc->sc_gc);
   1149  1.33  macallan 						vcons_redraw_screen(ms);
   1150  1.18    martin 					}
   1151  1.18    martin 				}
   1152  1.18    martin 			}
   1153  1.66  macallan 			return 0;
   1154  1.66  macallan 		case WSDISPLAYIO_GET_FBINFO:
   1155  1.66  macallan 			{
   1156  1.66  macallan 				struct wsdisplayio_fbinfo *fbi = data;
   1157  1.66  macallan 
   1158  1.66  macallan 				return wsdisplayio_get_fbinfo(&ms->scr_ri, fbi);
   1159  1.66  macallan 			}
   1160  1.18    martin 	}
   1161  1.18    martin 	return EPASSTHROUGH;
   1162  1.18    martin }
   1163  1.18    martin 
   1164  1.18    martin paddr_t
   1165  1.30      jmmv cgsix_mmap(void *v, void *vs, off_t offset, int prot)
   1166  1.18    martin {
   1167  1.33  macallan 	struct vcons_data *vd = v;
   1168  1.33  macallan 	struct cgsix_softc *sc = vd->cookie;
   1169  1.33  macallan 
   1170  1.52  macallan 	if (offset < sc->sc_ramsize) {
   1171  1.23  macallan 		return bus_space_mmap(sc->sc_bustag, sc->sc_paddr,
   1172  1.68  macallan 		    CGSIX_RAM_OFFSET + offset, prot,
   1173  1.68  macallan 		    BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE);
   1174  1.18    martin 	}
   1175  1.52  macallan 	return -1;
   1176  1.18    martin }
   1177  1.18    martin 
   1178  1.19     perry int
   1179  1.18    martin cgsix_putcmap(struct cgsix_softc *sc, struct wsdisplay_cmap *cm)
   1180  1.18    martin {
   1181  1.18    martin 	u_int index = cm->index;
   1182  1.18    martin 	u_int count = cm->count;
   1183  1.54  macallan 	int error, i;
   1184  1.54  macallan 
   1185  1.18    martin 	if (index >= 256 || count > 256 || index + count > 256)
   1186  1.18    martin 		return EINVAL;
   1187  1.18    martin 
   1188  1.23  macallan 	for (i = 0; i < count; i++)
   1189  1.18    martin 	{
   1190  1.22    martin 		error = copyin(&cm->red[i],
   1191  1.23  macallan 		    &sc->sc_cmap.cm_map[index + i][0], 1);
   1192  1.18    martin 		if (error)
   1193  1.18    martin 			return error;
   1194  1.22    martin 		error = copyin(&cm->green[i],
   1195  1.23  macallan 		    &sc->sc_cmap.cm_map[index + i][1],
   1196  1.22    martin 		    1);
   1197  1.18    martin 		if (error)
   1198  1.18    martin 			return error;
   1199  1.22    martin 		error = copyin(&cm->blue[i],
   1200  1.23  macallan 		    &sc->sc_cmap.cm_map[index + i][2], 1);
   1201  1.18    martin 		if (error)
   1202  1.18    martin 			return error;
   1203  1.18    martin 	}
   1204  1.23  macallan 	cg6_loadcmap(sc, index, count);
   1205  1.19     perry 
   1206  1.18    martin 	return 0;
   1207  1.18    martin }
   1208  1.18    martin 
   1209  1.22    martin int
   1210  1.22    martin cgsix_getcmap(struct cgsix_softc *sc, struct wsdisplay_cmap *cm)
   1211  1.18    martin {
   1212  1.18    martin 	u_int index = cm->index;
   1213  1.18    martin 	u_int count = cm->count;
   1214  1.18    martin 	int error,i;
   1215  1.18    martin 
   1216  1.18    martin 	if (index >= 256 || count > 256 || index + count > 256)
   1217  1.18    martin 		return EINVAL;
   1218  1.18    martin 
   1219  1.23  macallan 	for (i = 0; i < count; i++)
   1220  1.18    martin 	{
   1221  1.23  macallan 		error = copyout(&sc->sc_cmap.cm_map[index + i][0],
   1222  1.23  macallan 		    &cm->red[i], 1);
   1223  1.18    martin 		if (error)
   1224  1.18    martin 			return error;
   1225  1.23  macallan 		error = copyout(&sc->sc_cmap.cm_map[index + i][1],
   1226  1.23  macallan 		    &cm->green[i], 1);
   1227  1.18    martin 		if (error)
   1228  1.18    martin 			return error;
   1229  1.23  macallan 		error = copyout(&sc->sc_cmap.cm_map[index + i][2],
   1230  1.23  macallan 		    &cm->blue[i], 1);
   1231  1.18    martin 		if (error)
   1232  1.18    martin 			return error;
   1233  1.18    martin 	}
   1234  1.19     perry 
   1235  1.18    martin 	return 0;
   1236  1.18    martin }
   1237  1.23  macallan 
   1238  1.23  macallan void
   1239  1.33  macallan cgsix_init_screen(void *cookie, struct vcons_screen *scr,
   1240  1.23  macallan     int existing, long *defattr)
   1241  1.23  macallan {
   1242  1.33  macallan 	struct cgsix_softc *sc = cookie;
   1243  1.33  macallan 	struct rasops_info *ri = &scr->scr_ri;
   1244  1.60  macallan 	int av;
   1245  1.33  macallan 
   1246  1.23  macallan 	ri->ri_depth = 8;
   1247  1.23  macallan 	ri->ri_width = sc->sc_width;
   1248  1.23  macallan 	ri->ri_height = sc->sc_height;
   1249  1.23  macallan 	ri->ri_stride = sc->sc_stride;
   1250  1.60  macallan 	av = sc->sc_ramsize - (sc->sc_height * sc->sc_stride);
   1251  1.60  macallan 	ri->ri_flg = RI_CENTER  | RI_8BIT_IS_RGB;
   1252  1.60  macallan 	if (av > (128 * 1024)) {
   1253  1.68  macallan 		ri->ri_flg |= RI_ENABLE_ALPHA | RI_PREFER_ALPHA;
   1254  1.60  macallan 	}
   1255  1.23  macallan 	ri->ri_bits = sc->sc_fb.fb_pixels;
   1256  1.68  macallan 	scr->scr_flags |= VCONS_LOADFONT;
   1257  1.68  macallan 
   1258  1.51  macallan 	rasops_init(ri, 0, 0);
   1259  1.68  macallan 	ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_REVERSE |
   1260  1.68  macallan 		      WSSCREEN_UNDERLINE | WSSCREEN_RESIZE;
   1261  1.23  macallan 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
   1262  1.23  macallan 		    sc->sc_width / ri->ri_font->fontwidth);
   1263  1.23  macallan 
   1264  1.23  macallan 	/* enable acceleration */
   1265  1.23  macallan 	ri->ri_hw = scr;
   1266  1.23  macallan 	ri->ri_ops.copyrows = cg6_ras_copyrows;
   1267  1.23  macallan 	ri->ri_ops.copycols = cg6_ras_copycols;
   1268  1.23  macallan 	ri->ri_ops.eraserows = cg6_ras_eraserows;
   1269  1.23  macallan 	ri->ri_ops.erasecols = cg6_ras_erasecols;
   1270  1.23  macallan 	ri->ri_ops.cursor = cgsix_cursor;
   1271  1.57  macallan 	if (FONT_IS_ALPHA(ri->ri_font)) {
   1272  1.57  macallan 		ri->ri_ops.putchar = cgsix_putchar_aa;
   1273  1.57  macallan 	} else
   1274  1.57  macallan 		ri->ri_ops.putchar = cgsix_putchar;
   1275  1.23  macallan }
   1276  1.23  macallan 
   1277  1.23  macallan void
   1278  1.23  macallan cgsix_rectfill(struct cgsix_softc *sc, int xs, int ys, int wi, int he,
   1279  1.23  macallan     uint32_t col)
   1280  1.23  macallan {
   1281  1.23  macallan 	volatile struct cg6_fbc *fbc = sc->sc_fbc;
   1282  1.56  macallan 
   1283  1.56  macallan 	CG6_WAIT_READY(fbc);
   1284  1.55  macallan 
   1285  1.23  macallan 	fbc->fbc_alu = CG6_ALU_FILL;
   1286  1.55  macallan 	fbc->fbc_mode = GX_BLIT_SRC | GX_MODE_COLOR8;
   1287  1.55  macallan 
   1288  1.23  macallan 	fbc->fbc_fg = col;
   1289  1.23  macallan 	fbc->fbc_arecty = ys;
   1290  1.23  macallan 	fbc->fbc_arectx = xs;
   1291  1.23  macallan 	fbc->fbc_arecty = ys + he - 1;
   1292  1.23  macallan 	fbc->fbc_arectx = xs + wi - 1;
   1293  1.56  macallan 	CG6_DRAW(fbc);
   1294  1.23  macallan }
   1295  1.23  macallan 
   1296  1.57  macallan void
   1297  1.57  macallan cgsix_bitblt(void *cookie, int xs, int ys, int xd, int yd,
   1298  1.57  macallan     int wi, int he, int rop)
   1299  1.57  macallan {
   1300  1.57  macallan 	struct cgsix_softc *sc = cookie;
   1301  1.57  macallan 	volatile struct cg6_fbc *fbc = sc->sc_fbc;
   1302  1.57  macallan 	CG6_WAIT_READY(fbc);
   1303  1.57  macallan 
   1304  1.57  macallan 	fbc->fbc_alu = rop;
   1305  1.57  macallan 	fbc->fbc_mode = GX_BLIT_SRC | GX_MODE_COLOR8;
   1306  1.57  macallan 
   1307  1.57  macallan 	fbc->fbc_x0 = xs;
   1308  1.57  macallan 	fbc->fbc_y0 = ys;
   1309  1.57  macallan 	fbc->fbc_x1 = xs + wi - 1;
   1310  1.57  macallan 	fbc->fbc_y1 = ys + he - 1;
   1311  1.57  macallan 	fbc->fbc_x2 = xd;
   1312  1.57  macallan 	fbc->fbc_y2 = yd;
   1313  1.57  macallan 	fbc->fbc_x3 = xd + wi - 1;
   1314  1.57  macallan 	fbc->fbc_y3 = yd + he - 1;
   1315  1.57  macallan 	CG6_BLIT(fbc);
   1316  1.57  macallan }
   1317  1.57  macallan 
   1318  1.23  macallan void
   1319  1.23  macallan cgsix_setup_mono(struct cgsix_softc *sc, int x, int y, int wi, int he,
   1320  1.23  macallan     uint32_t fg, uint32_t bg)
   1321  1.23  macallan {
   1322  1.23  macallan 	volatile struct cg6_fbc *fbc=sc->sc_fbc;
   1323  1.56  macallan 
   1324  1.56  macallan 	CG6_WAIT_READY(fbc);
   1325  1.56  macallan 
   1326  1.23  macallan 	fbc->fbc_x0 = x;
   1327  1.54  macallan 	fbc->fbc_x1 = x + wi - 1;
   1328  1.23  macallan 	fbc->fbc_y0 = y;
   1329  1.23  macallan 	fbc->fbc_incx = 0;
   1330  1.23  macallan 	fbc->fbc_incy = 1;
   1331  1.23  macallan 	fbc->fbc_fg = fg;
   1332  1.23  macallan 	fbc->fbc_bg = bg;
   1333  1.53  macallan 	fbc->fbc_mode = GX_BLIT_NOSRC | GX_MODE_COLOR1;
   1334  1.53  macallan 	fbc->fbc_alu = GX_PATTERN_ONES | ROP_OSTP(GX_ROP_CLEAR, GX_ROP_SET);
   1335  1.23  macallan 	sc->sc_mono_width = wi;
   1336  1.23  macallan 	/* now feed the data into the chip */
   1337  1.23  macallan }
   1338  1.23  macallan 
   1339  1.23  macallan void
   1340  1.23  macallan cgsix_feed_line(struct cgsix_softc *sc, int count, uint8_t *data)
   1341  1.23  macallan {
   1342  1.23  macallan 	int i;
   1343  1.23  macallan 	uint32_t latch, res = 0, shift;
   1344  1.23  macallan 	volatile struct cg6_fbc *fbc = sc->sc_fbc;
   1345  1.23  macallan 
   1346  1.23  macallan 	if (sc->sc_mono_width > 32) {
   1347  1.23  macallan 		/* ARGH! */
   1348  1.23  macallan 	} else
   1349  1.23  macallan 	{
   1350  1.23  macallan 		shift = 24;
   1351  1.23  macallan 		for (i = 0; i < count; i++) {
   1352  1.23  macallan 			latch = data[i];
   1353  1.23  macallan 			res |= latch << shift;
   1354  1.23  macallan 			shift -= 8;
   1355  1.23  macallan 		}
   1356  1.23  macallan 		fbc->fbc_font = res;
   1357  1.23  macallan 	}
   1358  1.23  macallan }
   1359  1.23  macallan 
   1360  1.23  macallan void
   1361  1.23  macallan cgsix_putchar(void *cookie, int row, int col, u_int c, long attr)
   1362  1.23  macallan {
   1363  1.33  macallan 	struct rasops_info *ri = cookie;
   1364  1.47  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, c);
   1365  1.33  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1366  1.33  macallan 	struct cgsix_softc *sc = scr->scr_cookie;
   1367  1.33  macallan 	int inv;
   1368  1.23  macallan 
   1369  1.23  macallan 	if ((row >= 0) && (row < ri->ri_rows) && (col >= 0) &&
   1370  1.23  macallan 	    (col < ri->ri_cols)) {
   1371  1.23  macallan 
   1372  1.33  macallan 		if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
   1373  1.33  macallan 
   1374  1.23  macallan 			int fg, bg, uc, i;
   1375  1.23  macallan 			uint8_t *data;
   1376  1.23  macallan 			int x, y, wi, he;
   1377  1.23  macallan 			volatile struct cg6_fbc *fbc = sc->sc_fbc;
   1378  1.23  macallan 
   1379  1.47  macallan 			wi = font->fontwidth;
   1380  1.47  macallan 			he = font->fontheight;
   1381  1.23  macallan 
   1382  1.47  macallan 			if (!CHAR_IN_FONT(c, font))
   1383  1.23  macallan 				return;
   1384  1.33  macallan 			inv = ((attr >> 8) & WSATTR_REVERSE);
   1385  1.33  macallan 			if (inv) {
   1386  1.33  macallan 				fg = (u_char)ri->ri_devcmap[(attr >> 16) &
   1387  1.33  macallan 				    0xff];
   1388  1.33  macallan 				bg = (u_char)ri->ri_devcmap[(attr >> 24) &
   1389  1.33  macallan 				    0xff];
   1390  1.33  macallan 			} else {
   1391  1.33  macallan 				bg = (u_char)ri->ri_devcmap[(attr >> 16) &
   1392  1.33  macallan 				    0xff];
   1393  1.33  macallan 				fg = (u_char)ri->ri_devcmap[(attr >> 24) &
   1394  1.33  macallan 				    0xff];
   1395  1.33  macallan 			}
   1396  1.33  macallan 
   1397  1.23  macallan 			x = ri->ri_xorigin + col * wi;
   1398  1.23  macallan 			y = ri->ri_yorigin + row * he;
   1399  1.33  macallan 
   1400  1.23  macallan 			if (c == 0x20) {
   1401  1.23  macallan 				cgsix_rectfill(sc, x, y, wi, he, bg);
   1402  1.23  macallan 			} else {
   1403  1.47  macallan 				uc = c - font->firstchar;
   1404  1.47  macallan 				data = (uint8_t *)font->data + uc *
   1405  1.23  macallan 				    ri->ri_fontscale;
   1406  1.23  macallan 
   1407  1.23  macallan 				cgsix_setup_mono(sc, x, y, wi, 1, fg, bg);
   1408  1.23  macallan 				for (i = 0; i < he; i++) {
   1409  1.47  macallan 					cgsix_feed_line(sc, font->stride,
   1410  1.23  macallan 					    data);
   1411  1.47  macallan 					data += font->stride;
   1412  1.23  macallan 				}
   1413  1.23  macallan 				/* put the chip back to normal */
   1414  1.23  macallan 				fbc->fbc_incy = 0;
   1415  1.23  macallan 			}
   1416  1.23  macallan 		}
   1417  1.23  macallan 	}
   1418  1.23  macallan }
   1419  1.23  macallan 
   1420  1.23  macallan void
   1421  1.57  macallan cgsix_putchar_aa(void *cookie, int row, int col, u_int c, long attr)
   1422  1.57  macallan {
   1423  1.57  macallan 	struct rasops_info *ri = cookie;
   1424  1.57  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, c);
   1425  1.57  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1426  1.57  macallan 	struct cgsix_softc *sc = scr->scr_cookie;
   1427  1.57  macallan 	volatile struct cg6_fbc *fbc = sc->sc_fbc;
   1428  1.57  macallan 
   1429  1.57  macallan 	uint32_t bg, latch = 0, bg8, fg8, pixel;
   1430  1.57  macallan 	int i, j, shift, x, y, wi, he, r, g, b, aval;
   1431  1.57  macallan 	int r1, g1, b1, r0, g0, b0, fgo, bgo;
   1432  1.57  macallan 	uint8_t *data8;
   1433  1.57  macallan 	int rv;
   1434  1.57  macallan 
   1435  1.57  macallan 	if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL)
   1436  1.57  macallan 		return;
   1437  1.57  macallan 
   1438  1.57  macallan 	if (!CHAR_IN_FONT(c, font))
   1439  1.57  macallan 		return;
   1440  1.57  macallan 
   1441  1.57  macallan 	wi = font->fontwidth;
   1442  1.57  macallan 	he = font->fontheight;
   1443  1.57  macallan 
   1444  1.57  macallan 	bg = ri->ri_devcmap[(attr >> 16) & 0xf];
   1445  1.57  macallan 	x = ri->ri_xorigin + col * wi;
   1446  1.57  macallan 	y = ri->ri_yorigin + row * he;
   1447  1.57  macallan 	if (c == 0x20) {
   1448  1.57  macallan 		cgsix_rectfill(sc, x, y, wi, he, bg);
   1449  1.57  macallan 		return;
   1450  1.57  macallan 	}
   1451  1.57  macallan 
   1452  1.57  macallan 	rv = glyphcache_try(&sc->sc_gc, c, x, y, attr);
   1453  1.57  macallan 	if (rv == GC_OK)
   1454  1.57  macallan 		return;
   1455  1.57  macallan 
   1456  1.57  macallan 	data8 = WSFONT_GLYPH(c, font);
   1457  1.57  macallan 
   1458  1.57  macallan 	CG6_WAIT_READY(sc->sc_fbc);
   1459  1.57  macallan 	fbc->fbc_incx = 4;
   1460  1.57  macallan 	fbc->fbc_incy = 0;
   1461  1.57  macallan 	fbc->fbc_mode = GX_BLIT_NOSRC | GX_MODE_COLOR8;
   1462  1.57  macallan 	fbc->fbc_alu = CG6_ALU_COPY;
   1463  1.57  macallan 	fbc->fbc_clipmaxx = x + wi - 1;
   1464  1.57  macallan 
   1465  1.57  macallan 	/*
   1466  1.57  macallan 	 * we need the RGB colours here, so get offsets into rasops_cmap
   1467  1.57  macallan 	 */
   1468  1.57  macallan 	fgo = ((attr >> 24) & 0xf) * 3;
   1469  1.57  macallan 	bgo = ((attr >> 16) & 0xf) * 3;
   1470  1.57  macallan 
   1471  1.57  macallan 	r0 = rasops_cmap[bgo];
   1472  1.57  macallan 	r1 = rasops_cmap[fgo];
   1473  1.57  macallan 	g0 = rasops_cmap[bgo + 1];
   1474  1.57  macallan 	g1 = rasops_cmap[fgo + 1];
   1475  1.57  macallan 	b0 = rasops_cmap[bgo + 2];
   1476  1.57  macallan 	b1 = rasops_cmap[fgo + 2];
   1477  1.57  macallan #define R3G3B2(r, g, b) ((r & 0xe0) | ((g >> 3) & 0x1c) | (b >> 6))
   1478  1.57  macallan 	bg8 = R3G3B2(r0, g0, b0);
   1479  1.57  macallan 	fg8 = R3G3B2(r1, g1, b1);
   1480  1.57  macallan 
   1481  1.57  macallan 	for (i = 0; i < he; i++) {
   1482  1.57  macallan 
   1483  1.57  macallan 		CG6_WAIT_READY(fbc);
   1484  1.57  macallan 		fbc->fbc_x0 = x;
   1485  1.57  macallan 		fbc->fbc_x1 = x + 3;
   1486  1.57  macallan 		fbc->fbc_y0 = y + i;
   1487  1.57  macallan 
   1488  1.57  macallan 		shift = 24;
   1489  1.57  macallan 		for (j = 0; j < wi; j++) {
   1490  1.57  macallan 			aval = *data8;
   1491  1.57  macallan 			if (aval == 0) {
   1492  1.57  macallan 				pixel = bg8;
   1493  1.57  macallan 			} else if (aval == 255) {
   1494  1.57  macallan 				pixel = fg8;
   1495  1.57  macallan 			} else {
   1496  1.57  macallan 				r = aval * r1 + (255 - aval) * r0;
   1497  1.57  macallan 				g = aval * g1 + (255 - aval) * g0;
   1498  1.57  macallan 				b = aval * b1 + (255 - aval) * b0;
   1499  1.57  macallan 				pixel = ((r & 0xe000) >> 8) |
   1500  1.57  macallan 					((g & 0xe000) >> 11) |
   1501  1.57  macallan 					((b & 0xc000) >> 14);
   1502  1.57  macallan 			}
   1503  1.57  macallan 			data8++;
   1504  1.57  macallan 
   1505  1.57  macallan 			latch |= pixel << shift;
   1506  1.57  macallan 			if (shift == 0) {
   1507  1.57  macallan 				fbc->fbc_font = latch;
   1508  1.57  macallan 				latch = 0;
   1509  1.57  macallan 				shift = 24;
   1510  1.57  macallan 			} else
   1511  1.57  macallan 				shift -= 8;
   1512  1.57  macallan 		}
   1513  1.57  macallan 		if (shift != 24)
   1514  1.57  macallan 			fbc->fbc_font = latch;
   1515  1.57  macallan 	}
   1516  1.57  macallan 	fbc->fbc_clipmaxx = 0x3fff;
   1517  1.57  macallan 
   1518  1.57  macallan 	if (rv == GC_ADD) {
   1519  1.57  macallan 		glyphcache_add(&sc->sc_gc, c, x, y);
   1520  1.57  macallan 	}
   1521  1.57  macallan }
   1522  1.57  macallan 
   1523  1.57  macallan void
   1524  1.23  macallan cgsix_cursor(void *cookie, int on, int row, int col)
   1525  1.23  macallan {
   1526  1.33  macallan 	struct rasops_info *ri = cookie;
   1527  1.33  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1528  1.33  macallan 	struct cgsix_softc *sc = scr->scr_cookie;
   1529  1.23  macallan 	int x, y, wi, he;
   1530  1.23  macallan 
   1531  1.23  macallan 	wi = ri->ri_font->fontwidth;
   1532  1.23  macallan 	he = ri->ri_font->fontheight;
   1533  1.23  macallan 
   1534  1.33  macallan 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
   1535  1.33  macallan 		x = ri->ri_ccol * wi + ri->ri_xorigin;
   1536  1.33  macallan 		y = ri->ri_crow * he + ri->ri_yorigin;
   1537  1.33  macallan 		if (ri->ri_flg & RI_CURSOR) {
   1538  1.23  macallan 			cg6_invert(sc, x, y, wi, he);
   1539  1.33  macallan 			ri->ri_flg &= ~RI_CURSOR;
   1540  1.23  macallan 		}
   1541  1.33  macallan 		ri->ri_crow = row;
   1542  1.33  macallan 		ri->ri_ccol = col;
   1543  1.33  macallan 		if (on)
   1544  1.23  macallan 		{
   1545  1.33  macallan 			x = ri->ri_ccol * wi + ri->ri_xorigin;
   1546  1.33  macallan 			y = ri->ri_crow * he + ri->ri_yorigin;
   1547  1.23  macallan 			cg6_invert(sc, x, y, wi, he);
   1548  1.33  macallan 			ri->ri_flg |= RI_CURSOR;
   1549  1.23  macallan 		}
   1550  1.33  macallan 	} else
   1551  1.33  macallan 	{
   1552  1.33  macallan 		ri->ri_crow = row;
   1553  1.33  macallan 		ri->ri_ccol = col;
   1554  1.33  macallan 		ri->ri_flg &= ~RI_CURSOR;
   1555  1.23  macallan 	}
   1556  1.23  macallan }
   1557  1.23  macallan 
   1558  1.23  macallan void
   1559  1.23  macallan cgsix_clearscreen(struct cgsix_softc *sc)
   1560  1.23  macallan {
   1561  1.33  macallan 	struct rasops_info *ri = &cg6_console_screen.scr_ri;
   1562  1.23  macallan 
   1563  1.23  macallan 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
   1564  1.23  macallan 		volatile struct cg6_fbc *fbc = sc->sc_fbc;
   1565  1.23  macallan 
   1566  1.56  macallan 		CG6_WAIT_READY(fbc);
   1567  1.55  macallan 
   1568  1.23  macallan 		fbc->fbc_alu = CG6_ALU_FILL;
   1569  1.55  macallan 		fbc->fbc_mode = GX_BLIT_SRC | GX_MODE_COLOR8;
   1570  1.55  macallan 
   1571  1.23  macallan 		fbc->fbc_fg = ri->ri_devcmap[sc->sc_bg];
   1572  1.23  macallan 		fbc->fbc_arectx = 0;
   1573  1.23  macallan 		fbc->fbc_arecty = 0;
   1574  1.23  macallan 		fbc->fbc_arectx = ri->ri_width - 1;
   1575  1.23  macallan 		fbc->fbc_arecty = ri->ri_height - 1;
   1576  1.56  macallan 		CG6_DRAW(fbc);
   1577  1.23  macallan 	}
   1578  1.23  macallan }
   1579  1.23  macallan 
   1580  1.23  macallan void
   1581  1.23  macallan cg6_invert(struct cgsix_softc *sc, int x, int y, int wi, int he)
   1582  1.23  macallan {
   1583  1.23  macallan 	volatile struct cg6_fbc *fbc = sc->sc_fbc;
   1584  1.23  macallan 
   1585  1.56  macallan 	CG6_WAIT_READY(fbc);
   1586  1.56  macallan 
   1587  1.23  macallan 	fbc->fbc_alu = CG6_ALU_FLIP;
   1588  1.55  macallan 	fbc->fbc_mode = GX_BLIT_SRC | GX_MODE_COLOR8;
   1589  1.23  macallan 	fbc->fbc_arecty = y;
   1590  1.23  macallan 	fbc->fbc_arectx = x;
   1591  1.24  macallan 	fbc->fbc_arecty = y + he - 1;
   1592  1.24  macallan 	fbc->fbc_arectx = x + wi - 1;
   1593  1.56  macallan 	CG6_DRAW(fbc);
   1594  1.23  macallan }
   1595  1.23  macallan 
   1596