Home | History | Annotate | Line # | Download | only in sun
cgsix.c revision 1.20
      1  1.20    martin /*	$NetBSD: cgsix.c,v 1.20 2005/03/03 12:11:49 martin 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  * 3. All advertising materials mentioning features or use of this software
     19   1.1        pk  *    must display the following acknowledgement:
     20   1.1        pk  *        This product includes software developed by the NetBSD
     21   1.1        pk  *        Foundation, Inc. and its contributors.
     22   1.1        pk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1        pk  *    contributors may be used to endorse or promote products derived
     24   1.1        pk  *    from this software without specific prior written permission.
     25   1.1        pk  *
     26   1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1        pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1        pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1        pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1        pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1        pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1        pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1        pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1        pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1        pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1        pk  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1        pk  */
     38   1.1        pk 
     39   1.1        pk /*
     40   1.1        pk  * Copyright (c) 1993
     41   1.1        pk  *	The Regents of the University of California.  All rights reserved.
     42   1.1        pk  *
     43   1.1        pk  * This software was developed by the Computer Systems Engineering group
     44   1.1        pk  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     45   1.1        pk  * contributed to Berkeley.
     46   1.1        pk  *
     47   1.1        pk  * All advertising materials mentioning features or use of this software
     48   1.1        pk  * must display the following acknowledgement:
     49   1.1        pk  *	This product includes software developed by the University of
     50   1.1        pk  *	California, Lawrence Berkeley Laboratory.
     51   1.1        pk  *
     52   1.1        pk  * Redistribution and use in source and binary forms, with or without
     53   1.1        pk  * modification, are permitted provided that the following conditions
     54   1.1        pk  * are met:
     55   1.1        pk  * 1. Redistributions of source code must retain the above copyright
     56   1.1        pk  *    notice, this list of conditions and the following disclaimer.
     57   1.1        pk  * 2. Redistributions in binary form must reproduce the above copyright
     58   1.1        pk  *    notice, this list of conditions and the following disclaimer in the
     59   1.1        pk  *    documentation and/or other materials provided with the distribution.
     60  1.13       agc  * 3. Neither the name of the University nor the names of its contributors
     61   1.1        pk  *    may be used to endorse or promote products derived from this software
     62   1.1        pk  *    without specific prior written permission.
     63   1.1        pk  *
     64   1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     65   1.1        pk  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     66   1.1        pk  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     67   1.1        pk  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     68   1.1        pk  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     69   1.1        pk  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     70   1.1        pk  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     71   1.1        pk  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     72   1.1        pk  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     73   1.1        pk  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     74   1.1        pk  * SUCH DAMAGE.
     75   1.1        pk  *
     76   1.1        pk  *	@(#)cgsix.c	8.4 (Berkeley) 1/21/94
     77   1.1        pk  */
     78   1.1        pk 
     79   1.1        pk /*
     80   1.1        pk  * color display (cgsix) driver.
     81   1.1        pk  *
     82   1.1        pk  * Does not handle interrupts, even though they can occur.
     83   1.1        pk  *
     84   1.1        pk  * XXX should defer colormap updates to vertical retrace interrupts
     85   1.1        pk  */
     86   1.7     lukem 
     87   1.7     lukem #include <sys/cdefs.h>
     88  1.20    martin __KERNEL_RCSID(0, "$NetBSD: cgsix.c,v 1.20 2005/03/03 12:11:49 martin Exp $");
     89   1.1        pk 
     90   1.1        pk #include <sys/param.h>
     91   1.1        pk #include <sys/systm.h>
     92   1.1        pk #include <sys/buf.h>
     93   1.1        pk #include <sys/device.h>
     94   1.1        pk #include <sys/ioctl.h>
     95   1.1        pk #include <sys/malloc.h>
     96   1.1        pk #include <sys/mman.h>
     97   1.1        pk #include <sys/tty.h>
     98   1.1        pk #include <sys/conf.h>
     99   1.1        pk 
    100   1.1        pk #ifdef DEBUG
    101   1.1        pk #include <sys/proc.h>
    102   1.1        pk #include <sys/syslog.h>
    103   1.1        pk #endif
    104   1.1        pk 
    105   1.1        pk #include <uvm/uvm_extern.h>
    106   1.1        pk 
    107   1.1        pk #include <machine/bus.h>
    108   1.1        pk 
    109   1.1        pk #include <dev/sun/fbio.h>
    110   1.1        pk #include <dev/sun/fbvar.h>
    111   1.1        pk 
    112   1.1        pk #include <dev/sun/btreg.h>
    113   1.1        pk #include <dev/sun/btvar.h>
    114   1.1        pk #include <dev/sun/cgsixreg.h>
    115   1.1        pk #include <dev/sun/cgsixvar.h>
    116   1.1        pk #include <dev/sun/pfourreg.h>
    117   1.1        pk 
    118  1.18    martin #include <dev/wscons/wsconsio.h>
    119  1.18    martin #include <dev/wsfont/wsfont.h>
    120   1.1        pk #include <dev/rasops/rasops.h>
    121  1.18    martin 
    122  1.18    martin #include "opt_wsemul.h"
    123  1.20    martin #include "rasops_glue.h"
    124   1.1        pk 
    125   1.1        pk static void	cg6_unblank(struct device *);
    126   1.1        pk 
    127   1.8   gehenna extern struct cfdriver cgsix_cd;
    128   1.1        pk 
    129   1.8   gehenna dev_type_open(cgsixopen);
    130   1.8   gehenna dev_type_close(cgsixclose);
    131   1.8   gehenna dev_type_ioctl(cgsixioctl);
    132   1.8   gehenna dev_type_mmap(cgsixmmap);
    133   1.8   gehenna 
    134   1.8   gehenna const struct cdevsw cgsix_cdevsw = {
    135   1.8   gehenna 	cgsixopen, cgsixclose, noread, nowrite, cgsixioctl,
    136   1.9  jdolecek 	nostop, notty, nopoll, cgsixmmap, nokqfilter,
    137   1.8   gehenna };
    138   1.1        pk 
    139   1.1        pk /* frame buffer generic driver */
    140   1.1        pk static struct fbdriver cg6_fbdriver = {
    141   1.9  jdolecek 	cg6_unblank, cgsixopen, cgsixclose, cgsixioctl, nopoll, cgsixmmap,
    142   1.9  jdolecek 	nokqfilter
    143   1.1        pk };
    144   1.1        pk 
    145   1.1        pk static void cg6_reset (struct cgsix_softc *);
    146   1.1        pk static void cg6_loadcmap (struct cgsix_softc *, int, int);
    147   1.1        pk static void cg6_loadomap (struct cgsix_softc *);
    148   1.1        pk static void cg6_setcursor (struct cgsix_softc *);/* set position */
    149   1.1        pk static void cg6_loadcursor (struct cgsix_softc *);/* set shape */
    150   1.1        pk 
    151  1.18    martin struct wsscreen_descr cgsix_defaultscreen = {
    152  1.18    martin 	"std",
    153  1.18    martin 	0, 0,	/* will be filled in -- XXX shouldn't, it's global */
    154  1.18    martin 	0,		/* textops */
    155  1.18    martin 	0, 0,	/* font width/height */
    156  1.18    martin 	WSSCREEN_REVERSE	/* capabilities */
    157  1.18    martin };
    158  1.18    martin 
    159  1.18    martin static int cgsix_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
    160  1.18    martin static paddr_t cgsix_mmap __P((void *, off_t, int));
    161  1.18    martin static int cgsix_alloc_screen __P((void *, const struct wsscreen_descr *,
    162  1.18    martin 				void **, int *, int *, long *));
    163  1.18    martin static void cgsix_free_screen __P((void *, void *));
    164  1.18    martin static int cgsix_show_screen __P((void *, void *, int,
    165  1.18    martin 				void (*) (void *, int, int), void *));
    166  1.18    martin int cgsix_putcmap(struct cgsix_softc *, struct wsdisplay_cmap *);
    167  1.18    martin int cgsix_getcmap(struct cgsix_softc *, struct wsdisplay_cmap *);
    168  1.18    martin 
    169  1.18    martin struct wsdisplay_accessops cgsix_accessops = {
    170  1.18    martin 	cgsix_ioctl,
    171  1.18    martin 	cgsix_mmap,
    172  1.18    martin 	cgsix_alloc_screen,
    173  1.18    martin 	cgsix_free_screen,
    174  1.18    martin 	cgsix_show_screen,
    175  1.18    martin 	NULL, 	/* load_font */
    176  1.18    martin 	NULL,	/* pollc */
    177  1.18    martin 	NULL,	/* getwschar */
    178  1.18    martin 	NULL,	/* putwschar */
    179  1.18    martin 	NULL	/* scroll */
    180  1.18    martin };
    181  1.18    martin 
    182  1.18    martin const struct wsscreen_descr *_cgsix_scrlist[] = {
    183  1.18    martin 	&cgsix_defaultscreen
    184  1.18    martin };
    185  1.18    martin 
    186  1.18    martin struct wsscreen_list cgsix_screenlist = {
    187  1.18    martin 	sizeof(_cgsix_scrlist) / sizeof(struct wsscreen_descr *),
    188  1.18    martin 	_cgsix_scrlist
    189  1.18    martin };
    190  1.18    martin 
    191   1.1        pk #ifdef RASTERCONSOLE
    192   1.1        pk int cgsix_use_rasterconsole = 1;
    193  1.18    martin #endif
    194   1.1        pk 
    195   1.1        pk /*
    196   1.1        pk  * cg6 accelerated console routines.
    197   1.1        pk  *
    198   1.1        pk  * Note that buried in this code in several places is the assumption
    199   1.1        pk  * that pixels are exactly one byte wide.  Since this is cg6-specific
    200   1.1        pk  * code, this seems safe.  This assumption resides in things like the
    201   1.1        pk  * use of ri_emuwidth without messing around with ri_pelbytes, or the
    202   1.1        pk  * assumption that ri_font->fontwidth is the right thing to multiply
    203   1.1        pk  * character-cell counts by to get byte counts.
    204   1.1        pk  */
    205   1.1        pk 
    206   1.1        pk /*
    207   1.1        pk  * Magic values for blitter
    208   1.1        pk  */
    209   1.1        pk 
    210   1.5   tsutsui /* Values for the mode register */
    211   1.5   tsutsui #define CG6_MODE	(						\
    212   1.5   tsutsui 	  0x00200000 /* GX_BLIT_SRC */					\
    213   1.5   tsutsui 	| 0x00020000 /* GX_MODE_COLOR8 */				\
    214   1.5   tsutsui 	| 0x00008000 /* GX_DRAW_RENDER */				\
    215   1.5   tsutsui 	| 0x00002000 /* GX_BWRITE0_ENABLE */				\
    216   1.5   tsutsui 	| 0x00001000 /* GX_BWRITE1_DISABLE */				\
    217   1.5   tsutsui 	| 0x00000200 /* GX_BREAD_0 */					\
    218   1.5   tsutsui 	| 0x00000080 /* GX_BDISP_0 */					\
    219   1.5   tsutsui )
    220   1.5   tsutsui #define CG6_MODE_MASK	(						\
    221   1.5   tsutsui 	  0x00300000 /* GX_BLIT_ALL */					\
    222   1.5   tsutsui 	| 0x00060000 /* GX_MODE_ALL */					\
    223   1.5   tsutsui 	| 0x00018000 /* GX_DRAW_ALL */					\
    224   1.5   tsutsui 	| 0x00006000 /* GX_BWRITE0_ALL */				\
    225   1.5   tsutsui 	| 0x00001800 /* GX_BWRITE1_ALL */				\
    226   1.5   tsutsui 	| 0x00000600 /* GX_BREAD_ALL */					\
    227   1.5   tsutsui 	| 0x00000180 /* GX_BDISP_ALL */					\
    228   1.5   tsutsui )
    229   1.5   tsutsui 
    230   1.1        pk /* Value for the alu register for screen-to-screen copies */
    231   1.1        pk #define CG6_ALU_COPY	(						\
    232   1.1        pk 	  0x80000000 /* GX_PLANE_ONES (ignore planemask register) */	\
    233   1.1        pk 	| 0x20000000 /* GX_PIXEL_ONES (ignore pixelmask register) */	\
    234   1.1        pk 	| 0x00800000 /* GX_ATTR_SUPP (function unknown) */		\
    235   1.1        pk 	| 0x00000000 /* GX_RAST_BOOL (function unknown) */		\
    236   1.1        pk 	| 0x00000000 /* GX_PLOT_PLOT (function unknown) */		\
    237   1.1        pk 	| 0x08000000 /* GX_PATTERN_ONES (ignore pattern) */		\
    238   1.1        pk 	| 0x01000000 /* GX_POLYG_OVERLAP (unsure - handle overlap?) */	\
    239   1.1        pk 	| 0x0000cccc /* ALU = src */					\
    240   1.1        pk )
    241   1.1        pk 
    242   1.1        pk /* Value for the alu register for region fills */
    243   1.1        pk #define CG6_ALU_FILL	(						\
    244   1.1        pk 	  0x80000000 /* GX_PLANE_ONES (ignore planemask register) */	\
    245   1.1        pk 	| 0x20000000 /* GX_PIXEL_ONES (ignore pixelmask register) */	\
    246   1.1        pk 	| 0x00800000 /* GX_ATTR_SUPP (function unknown) */		\
    247   1.1        pk 	| 0x00000000 /* GX_RAST_BOOL (function unknown) */		\
    248   1.1        pk 	| 0x00000000 /* GX_PLOT_PLOT (function unknown) */		\
    249   1.1        pk 	| 0x08000000 /* GX_PATTERN_ONES (ignore pattern) */		\
    250   1.1        pk 	| 0x01000000 /* GX_POLYG_OVERLAP (unsure - handle overlap?) */	\
    251   1.1        pk 	| 0x0000ff00 /* ALU = fg color */				\
    252   1.1        pk )
    253   1.1        pk 
    254   1.1        pk /* Value for the alu register for toggling an area */
    255   1.1        pk #define CG6_ALU_FLIP	(						\
    256   1.1        pk 	  0x80000000 /* GX_PLANE_ONES (ignore planemask register) */	\
    257   1.1        pk 	| 0x20000000 /* GX_PIXEL_ONES (ignore pixelmask register) */	\
    258   1.1        pk 	| 0x00800000 /* GX_ATTR_SUPP (function unknown) */		\
    259   1.1        pk 	| 0x00000000 /* GX_RAST_BOOL (function unknown) */		\
    260   1.1        pk 	| 0x00000000 /* GX_PLOT_PLOT (function unknown) */		\
    261   1.1        pk 	| 0x08000000 /* GX_PATTERN_ONES (ignore pattern) */		\
    262   1.1        pk 	| 0x01000000 /* GX_POLYG_OVERLAP (unsure - handle overlap?) */	\
    263   1.1        pk 	| 0x00005555 /* ALU = ~dst */					\
    264   1.1        pk )
    265   1.1        pk 
    266   1.1        pk /*
    267   1.1        pk  * Wait for a blit to finish.
    268   1.1        pk  * 0x8000000 bit: function unknown; 0x20000000 bit: GX_BLT_INPROGRESS
    269   1.1        pk  */
    270   1.1        pk #define CG6_BLIT_WAIT(fbc) do {						\
    271   1.1        pk 	while (((fbc)->fbc_blit & 0xa0000000) == 0xa0000000)		\
    272   1.1        pk 		/*EMPTY*/;						\
    273   1.1        pk } while (0)
    274   1.1        pk 
    275   1.1        pk /*
    276   1.1        pk  * Wait for a drawing operation to finish, or at least get queued.
    277   1.1        pk  * 0x8000000 bit: function unknown; 0x20000000 bit: GX_FULL
    278   1.1        pk  */
    279   1.1        pk #define CG6_DRAW_WAIT(fbc) do {						\
    280   1.1        pk        	while (((fbc)->fbc_draw & 0xa0000000) == 0xa0000000)		\
    281   1.1        pk 		/*EMPTY*/;						\
    282   1.1        pk } while (0)
    283   1.1        pk 
    284   1.1        pk /*
    285   1.1        pk  * Wait for the whole engine to go idle.  This may not matter in our case;
    286   1.1        pk  * I'm not sure whether blits are actually queued or not.  It more likely
    287   1.1        pk  * is intended for lines and such that do get queued.
    288   1.1        pk  * 0x10000000 bit: GX_INPROGRESS
    289   1.1        pk  */
    290   1.1        pk #define CG6_DRAIN(fbc) do {						\
    291   1.1        pk 	while ((fbc)->fbc_s & 0x10000000)				\
    292   1.1        pk 		/*EMPTY*/;						\
    293   1.1        pk } while (0)
    294   1.1        pk 
    295  1.20    martin #if NWSDISPLAY
    296   1.5   tsutsui static void cg6_ras_init(struct cgsix_softc *);
    297   1.5   tsutsui static void cg6_ras_copyrows(void *, int, int, int);
    298   1.5   tsutsui static void cg6_ras_copycols(void *, int, int, int, int);
    299   1.5   tsutsui static void cg6_ras_erasecols(void *, int, int, int, long int);
    300   1.5   tsutsui static void cg6_ras_eraserows(void *, int, int, long int);
    301   1.5   tsutsui static void cg6_ras_do_cursor(struct rasops_info *);
    302   1.5   tsutsui 
    303   1.5   tsutsui static void
    304   1.5   tsutsui cg6_ras_init(struct cgsix_softc *sc)
    305   1.5   tsutsui {
    306   1.5   tsutsui 	volatile struct cg6_fbc *fbc = sc->sc_fbc;
    307   1.5   tsutsui 
    308   1.5   tsutsui 	CG6_DRAIN(fbc);
    309   1.5   tsutsui 	fbc->fbc_mode &= ~CG6_MODE_MASK;
    310   1.5   tsutsui 	fbc->fbc_mode |= CG6_MODE;
    311   1.5   tsutsui }
    312   1.5   tsutsui 
    313   1.1        pk static void
    314   1.1        pk cg6_ras_copyrows(void *cookie, int src, int dst, int n)
    315   1.1        pk {
    316   1.1        pk 	struct rasops_info *ri;
    317   1.1        pk 	volatile struct cg6_fbc *fbc;
    318   1.1        pk 
    319   1.1        pk 	ri = cookie;
    320   1.1        pk 	if (dst == src)
    321   1.1        pk 		return;
    322   1.1        pk 	if (src < 0) {
    323   1.1        pk 		n += src;
    324   1.1        pk 		src = 0;
    325   1.1        pk 	}
    326   1.1        pk 	if (src+n > ri->ri_rows)
    327   1.1        pk 		n = ri->ri_rows - src;
    328   1.1        pk 	if (dst < 0) {
    329   1.1        pk 		n += dst;
    330   1.1        pk 		dst = 0;
    331   1.1        pk 	}
    332   1.1        pk 	if (dst+n > ri->ri_rows)
    333   1.1        pk 		n = ri->ri_rows - dst;
    334   1.1        pk 	if (n <= 0)
    335   1.1        pk 		return;
    336   1.1        pk 	n *= ri->ri_font->fontheight;
    337   1.1        pk 	src *= ri->ri_font->fontheight;
    338   1.1        pk 	dst *= ri->ri_font->fontheight;
    339   1.1        pk 	fbc = ((struct cgsix_softc *)ri->ri_hw)->sc_fbc;
    340   1.1        pk 	fbc->fbc_clip = 0;
    341   1.1        pk 	fbc->fbc_s = 0;
    342   1.1        pk 	fbc->fbc_offx = 0;
    343   1.1        pk 	fbc->fbc_offy = 0;
    344   1.1        pk 	fbc->fbc_clipminx = 0;
    345   1.1        pk 	fbc->fbc_clipminy = 0;
    346   1.1        pk 	fbc->fbc_clipmaxx = ri->ri_width - 1;
    347   1.1        pk 	fbc->fbc_clipmaxy = ri->ri_height - 1;
    348   1.1        pk 	fbc->fbc_alu = CG6_ALU_COPY;
    349   1.1        pk 	fbc->fbc_x0 = ri->ri_xorigin;
    350   1.1        pk 	fbc->fbc_y0 = ri->ri_yorigin + src;
    351   1.1        pk 	fbc->fbc_x1 = ri->ri_xorigin + ri->ri_emuwidth - 1;
    352   1.1        pk 	fbc->fbc_y1 = ri->ri_yorigin + src + n - 1;
    353   1.1        pk 	fbc->fbc_x2 = ri->ri_xorigin;
    354   1.1        pk 	fbc->fbc_y2 = ri->ri_yorigin + dst;
    355   1.1        pk 	fbc->fbc_x3 = ri->ri_xorigin + ri->ri_emuwidth - 1;
    356   1.1        pk 	fbc->fbc_y3 = ri->ri_yorigin + dst + n - 1;
    357   1.1        pk 	CG6_BLIT_WAIT(fbc);
    358   1.1        pk 	CG6_DRAIN(fbc);
    359   1.1        pk }
    360   1.1        pk 
    361   1.1        pk static void
    362   1.1        pk cg6_ras_copycols(void *cookie, int row, int src, int dst, int n)
    363   1.1        pk {
    364   1.1        pk 	struct rasops_info *ri;
    365   1.1        pk 	volatile struct cg6_fbc *fbc;
    366   1.1        pk 
    367   1.1        pk 	ri = cookie;
    368   1.1        pk 	if (dst == src)
    369   1.1        pk 		return;
    370   1.1        pk 	if ((row < 0) || (row >= ri->ri_rows))
    371   1.1        pk 		return;
    372   1.1        pk 	if (src < 0) {
    373   1.1        pk 		n += src;
    374   1.1        pk 		src = 0;
    375   1.1        pk 	}
    376   1.1        pk 	if (src+n > ri->ri_cols)
    377   1.1        pk 		n = ri->ri_cols - src;
    378   1.1        pk 	if (dst < 0) {
    379   1.1        pk 		n += dst;
    380   1.1        pk 		dst = 0;
    381   1.1        pk 	}
    382   1.1        pk 	if (dst+n > ri->ri_cols)
    383   1.1        pk 		n = ri->ri_cols - dst;
    384   1.1        pk 	if (n <= 0)
    385   1.1        pk 		return;
    386   1.1        pk 	n *= ri->ri_font->fontwidth;
    387   1.1        pk 	src *= ri->ri_font->fontwidth;
    388   1.1        pk 	dst *= ri->ri_font->fontwidth;
    389   1.1        pk 	row *= ri->ri_font->fontheight;
    390   1.1        pk 	fbc = ((struct cgsix_softc *)ri->ri_hw)->sc_fbc;
    391   1.1        pk 	fbc->fbc_clip = 0;
    392   1.1        pk 	fbc->fbc_s = 0;
    393   1.1        pk 	fbc->fbc_offx = 0;
    394   1.1        pk 	fbc->fbc_offy = 0;
    395   1.1        pk 	fbc->fbc_clipminx = 0;
    396   1.1        pk 	fbc->fbc_clipminy = 0;
    397   1.1        pk 	fbc->fbc_clipmaxx = ri->ri_width - 1;
    398   1.1        pk 	fbc->fbc_clipmaxy = ri->ri_height - 1;
    399   1.1        pk 	fbc->fbc_alu = CG6_ALU_COPY;
    400   1.1        pk 	fbc->fbc_x0 = ri->ri_xorigin + src;
    401   1.1        pk 	fbc->fbc_y0 = ri->ri_yorigin + row;
    402   1.1        pk 	fbc->fbc_x1 = ri->ri_xorigin + src + n - 1;
    403   1.1        pk 	fbc->fbc_y1 = ri->ri_yorigin + row + ri->ri_font->fontheight - 1;
    404   1.1        pk 	fbc->fbc_x2 = ri->ri_xorigin + dst;
    405   1.1        pk 	fbc->fbc_y2 = ri->ri_yorigin + row;
    406   1.1        pk 	fbc->fbc_x3 = ri->ri_xorigin + dst + n - 1;
    407   1.1        pk 	fbc->fbc_y3 = ri->ri_yorigin + row + ri->ri_font->fontheight - 1;
    408   1.1        pk 	CG6_BLIT_WAIT(fbc);
    409   1.1        pk 	CG6_DRAIN(fbc);
    410   1.1        pk }
    411   1.1        pk 
    412   1.1        pk static void
    413   1.1        pk cg6_ras_erasecols(void *cookie, int row, int col, int n, long int attr)
    414   1.1        pk {
    415   1.1        pk 	struct rasops_info *ri;
    416   1.1        pk 	volatile struct cg6_fbc *fbc;
    417   1.1        pk 
    418   1.1        pk 	ri = cookie;
    419   1.1        pk 	if ((row < 0) || (row >= ri->ri_rows))
    420   1.1        pk 		return;
    421   1.1        pk 	if (col < 0) {
    422   1.1        pk 		n += col;
    423   1.1        pk 		col = 0;
    424   1.1        pk 	}
    425   1.1        pk 	if (col+n > ri->ri_cols)
    426   1.1        pk 		n = ri->ri_cols - col;
    427   1.1        pk 	if (n <= 0)
    428   1.1        pk 		return;
    429   1.1        pk 	n *= ri->ri_font->fontwidth;
    430   1.1        pk 	col *= ri->ri_font->fontwidth;
    431   1.1        pk 	row *= ri->ri_font->fontheight;
    432   1.1        pk 	fbc = ((struct cgsix_softc *)ri->ri_hw)->sc_fbc;
    433   1.1        pk 	fbc->fbc_clip = 0;
    434   1.1        pk 	fbc->fbc_s = 0;
    435   1.1        pk 	fbc->fbc_offx = 0;
    436   1.1        pk 	fbc->fbc_offy = 0;
    437   1.1        pk 	fbc->fbc_clipminx = 0;
    438   1.1        pk 	fbc->fbc_clipminy = 0;
    439   1.1        pk 	fbc->fbc_clipmaxx = ri->ri_width - 1;
    440   1.1        pk 	fbc->fbc_clipmaxy = ri->ri_height - 1;
    441   1.1        pk 	fbc->fbc_alu = CG6_ALU_FILL;
    442   1.1        pk 	fbc->fbc_fg = ri->ri_devcmap[(attr >> 16) & 0xf];
    443   1.1        pk 	fbc->fbc_arecty = ri->ri_yorigin + row;
    444   1.1        pk 	fbc->fbc_arectx = ri->ri_xorigin + col;
    445   1.1        pk 	fbc->fbc_arecty = ri->ri_yorigin + row + ri->ri_font->fontheight - 1;
    446   1.1        pk 	fbc->fbc_arectx = ri->ri_xorigin + col + n - 1;
    447   1.1        pk 	CG6_DRAW_WAIT(fbc);
    448   1.1        pk 	CG6_DRAIN(fbc);
    449   1.1        pk }
    450   1.1        pk 
    451   1.1        pk static void
    452   1.1        pk cg6_ras_eraserows(void *cookie, int row, int n, long int attr)
    453   1.1        pk {
    454   1.1        pk 	struct rasops_info *ri;
    455   1.1        pk 	volatile struct cg6_fbc *fbc;
    456   1.1        pk 
    457   1.1        pk 	ri = cookie;
    458   1.1        pk 	if (row < 0) {
    459   1.1        pk 		n += row;
    460   1.1        pk 		row = 0;
    461   1.1        pk 	}
    462   1.1        pk 	if (row+n > ri->ri_rows)
    463   1.1        pk 		n = ri->ri_rows - row;
    464   1.1        pk 	if (n <= 0)
    465   1.1        pk 		return;
    466   1.1        pk 	fbc = ((struct cgsix_softc *)ri->ri_hw)->sc_fbc;
    467   1.1        pk 	fbc->fbc_clip = 0;
    468   1.1        pk 	fbc->fbc_s = 0;
    469   1.1        pk 	fbc->fbc_offx = 0;
    470   1.1        pk 	fbc->fbc_offy = 0;
    471   1.1        pk 	fbc->fbc_clipminx = 0;
    472   1.1        pk 	fbc->fbc_clipminy = 0;
    473   1.1        pk 	fbc->fbc_clipmaxx = ri->ri_width - 1;
    474   1.1        pk 	fbc->fbc_clipmaxy = ri->ri_height - 1;
    475   1.1        pk 	fbc->fbc_alu = CG6_ALU_FILL;
    476   1.1        pk 	fbc->fbc_fg = ri->ri_devcmap[(attr >> 16) & 0xf];
    477   1.1        pk 	if ((n == ri->ri_rows) && (ri->ri_flg & RI_FULLCLEAR)) {
    478   1.1        pk 		fbc->fbc_arecty = 0;
    479   1.1        pk 		fbc->fbc_arectx = 0;
    480   1.1        pk 		fbc->fbc_arecty = ri->ri_height - 1;
    481   1.1        pk 		fbc->fbc_arectx = ri->ri_width - 1;
    482   1.1        pk 	} else {
    483   1.1        pk 		row *= ri->ri_font->fontheight;
    484   1.1        pk 		fbc->fbc_arecty = ri->ri_yorigin + row;
    485   1.1        pk 		fbc->fbc_arectx = ri->ri_xorigin;
    486   1.1        pk 		fbc->fbc_arecty = ri->ri_yorigin + row + (n * ri->ri_font->fontheight) - 1;
    487   1.1        pk 		fbc->fbc_arectx = ri->ri_xorigin + ri->ri_emuwidth - 1;
    488   1.1        pk 	}
    489   1.1        pk 	CG6_DRAW_WAIT(fbc);
    490   1.1        pk 	CG6_DRAIN(fbc);
    491   1.1        pk }
    492   1.1        pk 
    493   1.1        pk /*
    494   1.1        pk  * Really want something more like fg^bg here, but that would be more
    495   1.1        pk  * or less impossible to migrate to colors.  So we hope there's
    496   1.1        pk  * something not too inappropriate in the colormap...besides, it's what
    497   1.1        pk  * the non-accelerated code did. :-)
    498   1.1        pk  */
    499   1.1        pk static void
    500   1.1        pk cg6_ras_do_cursor(struct rasops_info *ri)
    501   1.1        pk {
    502   1.1        pk 	volatile struct cg6_fbc *fbc;
    503   1.1        pk 	int row;
    504   1.1        pk 	int col;
    505   1.1        pk 
    506   1.1        pk 	row = ri->ri_crow * ri->ri_font->fontheight;
    507   1.1        pk 	col = ri->ri_ccol * ri->ri_font->fontwidth;
    508   1.1        pk 	fbc = ((struct cgsix_softc *)ri->ri_hw)->sc_fbc;
    509   1.1        pk 	fbc->fbc_clip = 0;
    510   1.1        pk 	fbc->fbc_s = 0;
    511   1.1        pk 	fbc->fbc_offx = 0;
    512   1.1        pk 	fbc->fbc_offy = 0;
    513   1.1        pk 	fbc->fbc_clipminx = 0;
    514   1.1        pk 	fbc->fbc_clipminy = 0;
    515   1.1        pk 	fbc->fbc_clipmaxx = ri->ri_width - 1;
    516   1.1        pk 	fbc->fbc_clipmaxy = ri->ri_height - 1;
    517   1.1        pk 	fbc->fbc_alu = CG6_ALU_FLIP;
    518   1.1        pk 	fbc->fbc_arecty = ri->ri_yorigin + row;
    519   1.1        pk 	fbc->fbc_arectx = ri->ri_xorigin + col;
    520   1.1        pk 	fbc->fbc_arecty = ri->ri_yorigin + row + ri->ri_font->fontheight - 1;
    521   1.1        pk 	fbc->fbc_arectx = ri->ri_xorigin + col + ri->ri_font->fontwidth - 1;
    522   1.1        pk 	CG6_DRAW_WAIT(fbc);
    523   1.1        pk 	CG6_DRAIN(fbc);
    524   1.1        pk }
    525  1.20    martin #endif
    526   1.1        pk 
    527   1.1        pk void
    528   1.1        pk cg6attach(sc, name, isconsole)
    529   1.1        pk 	struct cgsix_softc *sc;
    530   1.1        pk 	char *name;
    531   1.1        pk 	int isconsole;
    532   1.1        pk {
    533   1.1        pk 	struct fbdevice *fb = &sc->sc_fb;
    534  1.20    martin #if NWSDISPLAY
    535  1.18    martin 	struct wsemuldisplaydev_attach_args aa;
    536  1.18    martin 	struct rasops_info *ri = &fb->fb_rinfo;
    537  1.18    martin 	unsigned long defattr;
    538  1.20    martin #endif
    539   1.1        pk 
    540   1.1        pk 	fb->fb_driver = &cg6_fbdriver;
    541   1.1        pk 
    542   1.1        pk 	/* Don't have to map the pfour register on the cgsix. */
    543   1.1        pk 	fb->fb_pfour = NULL;
    544   1.1        pk 
    545   1.1        pk 	fb->fb_type.fb_cmsize = 256;
    546   1.1        pk 	fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
    547   1.1        pk 	printf(": %s, %d x %d", name,
    548   1.1        pk 	       fb->fb_type.fb_width, fb->fb_type.fb_height);
    549  1.18    martin 	if(sc->sc_fhc) {
    550   1.1        pk 	sc->sc_fhcrev = (*sc->sc_fhc >> FHC_REV_SHIFT) &
    551   1.1        pk 			(FHC_REV_MASK >> FHC_REV_SHIFT);
    552  1.18    martin 	} else
    553  1.18    martin 		sc->sc_fhcrev=-1;
    554   1.1        pk 	printf(", rev %d", sc->sc_fhcrev);
    555   1.1        pk 
    556   1.1        pk 	/* reset cursor & frame buffer controls */
    557   1.1        pk 	cg6_reset(sc);
    558   1.1        pk 
    559   1.1        pk 	/* enable video */
    560   1.1        pk 	sc->sc_thc->thc_misc |= THC_MISC_VIDEN;
    561   1.1        pk 
    562   1.1        pk 	if (isconsole) {
    563   1.1        pk 		printf(" (console)");
    564  1.19     perry 
    565  1.19     perry /* this is the old console attachment stuff - we shouldn't need it anymore */
    566   1.1        pk #ifdef RASTERCONSOLE
    567   1.1        pk 		if (cgsix_use_rasterconsole) {
    568   1.1        pk 			fbrcons_init(&sc->sc_fb);
    569   1.1        pk 			sc->sc_fb.fb_rinfo.ri_hw = sc;
    570   1.1        pk 			sc->sc_fb.fb_rinfo.ri_ops.copyrows = cg6_ras_copyrows;
    571   1.1        pk 			sc->sc_fb.fb_rinfo.ri_ops.copycols = cg6_ras_copycols;
    572   1.1        pk 			sc->sc_fb.fb_rinfo.ri_ops.erasecols = cg6_ras_erasecols;
    573   1.1        pk 			sc->sc_fb.fb_rinfo.ri_ops.eraserows = cg6_ras_eraserows;
    574   1.1        pk 			sc->sc_fb.fb_rinfo.ri_do_cursor = cg6_ras_do_cursor;
    575   1.5   tsutsui 			cg6_ras_init(sc);
    576   1.1        pk 		}
    577   1.1        pk #endif
    578   1.1        pk 	}
    579   1.1        pk 
    580  1.18    martin 	fb_attach(&sc->sc_fb, isconsole);
    581  1.19     perry 
    582  1.20    martin #if NWSDISPLAY
    583  1.20    martin 	/* setup rasops and so on for wsdisplay */
    584  1.18    martin 	wsfont_init();
    585  1.18    martin 	/* fill in rasops_info */
    586  1.18    martin 	ri->ri_hw=sc;
    587  1.18    martin 	ri->ri_width = fb->fb_type.fb_width;
    588  1.18    martin 	ri->ri_height = fb->fb_type.fb_height;
    589  1.18    martin 	ri->ri_depth = 8;
    590  1.18    martin 	ri->ri_stride = fb->fb_linebytes;
    591  1.18    martin 	ri->ri_bits = fb->fb_pixels;
    592  1.18    martin 	ri->ri_flg = RI_FORCEMONO | RI_CENTER | RI_CLEAR;
    593  1.18    martin 	rasops_init(ri, fb->fb_type.fb_height/16, fb->fb_type.fb_width/8);
    594  1.18    martin 	ri->ri_ops.copyrows = cg6_ras_copyrows;
    595  1.18    martin 	ri->ri_ops.copycols = cg6_ras_copycols;
    596  1.18    martin 	ri->ri_ops.erasecols = cg6_ras_erasecols;
    597  1.18    martin 	ri->ri_ops.eraserows = cg6_ras_eraserows;
    598  1.18    martin 	ri->ri_do_cursor = cg6_ras_do_cursor;
    599  1.18    martin 	cg6_ras_init(sc);
    600  1.18    martin 	cgsix_defaultscreen.nrows = ri->ri_rows;
    601  1.18    martin 	cgsix_defaultscreen.ncols = ri->ri_cols;
    602  1.18    martin 	cgsix_defaultscreen.textops = &ri->ri_ops;
    603  1.18    martin 	cgsix_defaultscreen.capabilities = ri->ri_caps;
    604  1.18    martin 	if(isconsole) {
    605  1.18    martin 		(*ri->ri_ops.allocattr)(ri, 0,0,0, &defattr);
    606  1.18    martin 		wsdisplay_cnattach(&cgsix_defaultscreen, ri, 0, 0, defattr);
    607  1.18    martin 	}
    608  1.19     perry 
    609  1.19     perry /* set up a colour map matching the terminal emulation in use */
    610  1.18    martin #ifdef WSEMUL_SUN
    611  1.19     perry 	sc->sc_cmap.cm_map[0][0]=255;
    612  1.19     perry 	sc->sc_cmap.cm_map[0][1]=255;
    613  1.19     perry 	sc->sc_cmap.cm_map[0][2]=255;
    614  1.19     perry 	sc->sc_cmap.cm_map[254][0]=255;
    615  1.19     perry 	sc->sc_cmap.cm_map[254][1]=255;
    616  1.19     perry 	sc->sc_cmap.cm_map[254][2]=255;
    617  1.19     perry 	sc->sc_cmap.cm_map[1][0]=0;
    618  1.19     perry 	sc->sc_cmap.cm_map[1][1]=0;
    619  1.19     perry 	sc->sc_cmap.cm_map[1][2]=0;
    620  1.19     perry 	sc->sc_cmap.cm_map[255][0]=0;
    621  1.19     perry 	sc->sc_cmap.cm_map[255][1]=0;
    622  1.19     perry 	sc->sc_cmap.cm_map[255][2]=0;
    623  1.18    martin 	cg6_loadcmap(sc,0,256);
    624  1.18    martin #elif defined(WSEMUL_VT100)
    625  1.18    martin 	/* here we should steal the VT100 colour map from rasops */
    626  1.19     perry #endif
    627  1.18    martin 
    628  1.18    martin 	aa.console = isconsole;
    629  1.18    martin 	aa.scrdata = &cgsix_screenlist;
    630  1.18    martin 	aa.accessops = &cgsix_accessops;
    631  1.18    martin 	aa.accesscookie = sc;
    632   1.1        pk 	printf("\n");
    633  1.18    martin 
    634  1.18    martin 	config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
    635  1.20    martin #endif
    636  1.18    martin 
    637   1.1        pk }
    638   1.1        pk 
    639   1.1        pk 
    640   1.1        pk int
    641  1.12      fvdl cgsixopen(dev, flags, mode, p)
    642   1.1        pk 	dev_t dev;
    643   1.1        pk 	int flags, mode;
    644  1.12      fvdl 	struct proc *p;
    645   1.1        pk {
    646   1.1        pk 	int unit = minor(dev);
    647   1.1        pk 
    648   1.1        pk 	if (unit >= cgsix_cd.cd_ndevs || cgsix_cd.cd_devs[unit] == NULL)
    649   1.1        pk 		return (ENXIO);
    650   1.1        pk 	return (0);
    651   1.1        pk }
    652   1.1        pk 
    653   1.1        pk int
    654  1.12      fvdl cgsixclose(dev, flags, mode, p)
    655   1.1        pk 	dev_t dev;
    656   1.1        pk 	int flags, mode;
    657  1.12      fvdl 	struct proc *p;
    658   1.1        pk {
    659   1.1        pk 	struct cgsix_softc *sc = cgsix_cd.cd_devs[minor(dev)];
    660   1.1        pk 
    661   1.1        pk 	cg6_reset(sc);
    662   1.1        pk 
    663   1.1        pk 	/* (re-)initialize the default color map */
    664   1.1        pk 	bt_initcmap(&sc->sc_cmap, 256);
    665   1.1        pk 	cg6_loadcmap(sc, 0, 256);
    666   1.1        pk 
    667   1.1        pk 	return (0);
    668   1.1        pk }
    669   1.1        pk 
    670   1.1        pk int
    671  1.12      fvdl cgsixioctl(dev, cmd, data, flags, p)
    672   1.1        pk 	dev_t dev;
    673   1.1        pk 	u_long cmd;
    674   1.1        pk 	caddr_t data;
    675   1.1        pk 	int flags;
    676  1.12      fvdl 	struct proc *p;
    677   1.1        pk {
    678   1.1        pk 	struct cgsix_softc *sc = cgsix_cd.cd_devs[minor(dev)];
    679  1.16       chs 	union cursor_cmap tcm;
    680  1.16       chs 	uint32_t image[32], mask[32];
    681   1.1        pk 	u_int count;
    682   1.1        pk 	int v, error;
    683   1.1        pk 
    684  1.18    martin #ifdef CGSIX_DEBUG
    685  1.18    martin 	printf("cgsixioctl(%ld)\n",cmd);
    686  1.18    martin #endif
    687  1.18    martin 
    688   1.1        pk 	switch (cmd) {
    689   1.1        pk 
    690   1.1        pk 	case FBIOGTYPE:
    691   1.1        pk 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    692   1.1        pk 		break;
    693   1.1        pk 
    694   1.1        pk 	case FBIOGATTR:
    695   1.1        pk #define fba ((struct fbgattr *)data)
    696   1.1        pk 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    697   1.1        pk 		fba->owner = 0;		/* XXX ??? */
    698   1.1        pk 		fba->fbtype = sc->sc_fb.fb_type;
    699   1.1        pk 		fba->sattr.flags = 0;
    700   1.1        pk 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    701   1.1        pk 		fba->sattr.dev_specific[0] = -1;
    702   1.1        pk 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    703   1.1        pk 		fba->emu_types[1] = -1;
    704   1.1        pk #undef fba
    705   1.1        pk 		break;
    706   1.1        pk 
    707   1.1        pk 	case FBIOGETCMAP:
    708   1.1        pk #define	p ((struct fbcmap *)data)
    709   1.1        pk 		return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
    710   1.1        pk 
    711   1.1        pk 	case FBIOPUTCMAP:
    712   1.1        pk 		/* copy to software map */
    713   1.1        pk 		error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
    714   1.1        pk 		if (error)
    715   1.1        pk 			return (error);
    716   1.1        pk 		/* now blast them into the chip */
    717   1.1        pk 		/* XXX should use retrace interrupt */
    718   1.1        pk 		cg6_loadcmap(sc, p->index, p->count);
    719   1.1        pk #undef p
    720   1.1        pk 		break;
    721   1.1        pk 
    722   1.1        pk 	case FBIOGVIDEO:
    723   1.1        pk 		*(int *)data = sc->sc_blanked;
    724   1.1        pk 		break;
    725   1.1        pk 
    726   1.1        pk 	case FBIOSVIDEO:
    727   1.1        pk 		if (*(int *)data)
    728   1.1        pk 			cg6_unblank(&sc->sc_dev);
    729   1.1        pk 		else if (!sc->sc_blanked) {
    730   1.1        pk 			sc->sc_blanked = 1;
    731   1.1        pk 			sc->sc_thc->thc_misc &= ~THC_MISC_VIDEN;
    732   1.1        pk 		}
    733   1.1        pk 		break;
    734   1.1        pk 
    735   1.1        pk /* these are for both FBIOSCURSOR and FBIOGCURSOR */
    736   1.1        pk #define p ((struct fbcursor *)data)
    737   1.1        pk #define cc (&sc->sc_cursor)
    738   1.1        pk 
    739   1.1        pk 	case FBIOGCURSOR:
    740   1.1        pk 		/* do not quite want everything here... */
    741   1.1        pk 		p->set = FB_CUR_SETALL;	/* close enough, anyway */
    742   1.1        pk 		p->enable = cc->cc_enable;
    743   1.1        pk 		p->pos = cc->cc_pos;
    744   1.1        pk 		p->hot = cc->cc_hot;
    745   1.1        pk 		p->size = cc->cc_size;
    746   1.1        pk 
    747   1.1        pk 		/* begin ugh ... can we lose some of this crap?? */
    748   1.1        pk 		if (p->image != NULL) {
    749   1.1        pk 			count = cc->cc_size.y * 32 / NBBY;
    750  1.16       chs 			error = copyout(cc->cc_bits[1], p->image, count);
    751   1.1        pk 			if (error)
    752   1.1        pk 				return (error);
    753  1.16       chs 			error = copyout(cc->cc_bits[0], p->mask, count);
    754   1.1        pk 			if (error)
    755   1.1        pk 				return (error);
    756   1.1        pk 		}
    757   1.1        pk 		if (p->cmap.red != NULL) {
    758   1.1        pk 			error = bt_getcmap(&p->cmap,
    759   1.1        pk 			    (union bt_cmap *)&cc->cc_color, 2, 1);
    760   1.1        pk 			if (error)
    761   1.1        pk 				return (error);
    762   1.1        pk 		} else {
    763   1.1        pk 			p->cmap.index = 0;
    764   1.1        pk 			p->cmap.count = 2;
    765   1.1        pk 		}
    766   1.1        pk 		/* end ugh */
    767   1.1        pk 		break;
    768   1.1        pk 
    769   1.1        pk 	case FBIOSCURSOR:
    770   1.1        pk 		/*
    771   1.1        pk 		 * For setcmap and setshape, verify parameters, so that
    772   1.1        pk 		 * we do not get halfway through an update and then crap
    773   1.1        pk 		 * out with the software state screwed up.
    774   1.1        pk 		 */
    775   1.1        pk 		v = p->set;
    776   1.1        pk 		if (v & FB_CUR_SETCMAP) {
    777   1.1        pk 			/*
    778   1.1        pk 			 * This use of a temporary copy of the cursor
    779   1.1        pk 			 * colormap is not terribly efficient, but these
    780   1.1        pk 			 * copies are small (8 bytes)...
    781   1.1        pk 			 */
    782   1.1        pk 			tcm = cc->cc_color;
    783   1.1        pk 			error = bt_putcmap(&p->cmap, (union bt_cmap *)&tcm, 2, 1);
    784   1.1        pk 			if (error)
    785   1.1        pk 				return (error);
    786   1.1        pk 		}
    787   1.1        pk 		if (v & FB_CUR_SETSHAPE) {
    788   1.1        pk 			if ((u_int)p->size.x > 32 || (u_int)p->size.y > 32)
    789   1.1        pk 				return (EINVAL);
    790   1.1        pk 			count = p->size.y * 32 / NBBY;
    791  1.16       chs 			error = copyin(p->image, image, count);
    792  1.16       chs 			if (error)
    793  1.16       chs 				return error;
    794  1.16       chs 			error = copyin(p->mask, mask, count);
    795  1.16       chs 			if (error)
    796  1.16       chs 				return error;
    797   1.1        pk 		}
    798   1.1        pk 
    799   1.1        pk 		/* parameters are OK; do it */
    800   1.1        pk 		if (v & (FB_CUR_SETCUR | FB_CUR_SETPOS | FB_CUR_SETHOT)) {
    801   1.1        pk 			if (v & FB_CUR_SETCUR)
    802   1.1        pk 				cc->cc_enable = p->enable;
    803   1.1        pk 			if (v & FB_CUR_SETPOS)
    804   1.1        pk 				cc->cc_pos = p->pos;
    805   1.1        pk 			if (v & FB_CUR_SETHOT)
    806   1.1        pk 				cc->cc_hot = p->hot;
    807   1.1        pk 			cg6_setcursor(sc);
    808   1.1        pk 		}
    809   1.1        pk 		if (v & FB_CUR_SETCMAP) {
    810   1.1        pk 			cc->cc_color = tcm;
    811   1.1        pk 			cg6_loadomap(sc); /* XXX defer to vertical retrace */
    812   1.1        pk 		}
    813   1.1        pk 		if (v & FB_CUR_SETSHAPE) {
    814   1.1        pk 			cc->cc_size = p->size;
    815   1.1        pk 			count = p->size.y * 32 / NBBY;
    816  1.16       chs 			memset(cc->cc_bits, 0, sizeof cc->cc_bits);
    817  1.16       chs 			memcpy(cc->cc_bits[1], image, count);
    818  1.16       chs 			memcpy(cc->cc_bits[0], mask, count);
    819   1.1        pk 			cg6_loadcursor(sc);
    820   1.1        pk 		}
    821   1.1        pk 		break;
    822   1.1        pk 
    823   1.1        pk #undef p
    824   1.1        pk #undef cc
    825   1.1        pk 
    826   1.1        pk 	case FBIOGCURPOS:
    827   1.1        pk 		*(struct fbcurpos *)data = sc->sc_cursor.cc_pos;
    828   1.1        pk 		break;
    829   1.1        pk 
    830   1.1        pk 	case FBIOSCURPOS:
    831   1.1        pk 		sc->sc_cursor.cc_pos = *(struct fbcurpos *)data;
    832   1.1        pk 		cg6_setcursor(sc);
    833   1.1        pk 		break;
    834   1.1        pk 
    835   1.1        pk 	case FBIOGCURMAX:
    836   1.1        pk 		/* max cursor size is 32x32 */
    837   1.1        pk 		((struct fbcurpos *)data)->x = 32;
    838   1.1        pk 		((struct fbcurpos *)data)->y = 32;
    839   1.1        pk 		break;
    840   1.1        pk 
    841   1.1        pk 	default:
    842   1.1        pk #ifdef DEBUG
    843   1.1        pk 		log(LOG_NOTICE, "cgsixioctl(0x%lx) (%s[%d])\n", cmd,
    844   1.1        pk 		    p->p_comm, p->p_pid);
    845   1.1        pk #endif
    846   1.1        pk 		return (ENOTTY);
    847   1.1        pk 	}
    848   1.1        pk 	return (0);
    849   1.1        pk }
    850   1.1        pk 
    851   1.1        pk /*
    852   1.1        pk  * Clean up hardware state (e.g., after bootup or after X crashes).
    853   1.1        pk  */
    854   1.1        pk static void
    855   1.1        pk cg6_reset(sc)
    856   1.1        pk 	struct cgsix_softc *sc;
    857   1.1        pk {
    858   1.1        pk 	volatile struct cg6_tec_xxx *tec;
    859   1.1        pk 	int fhc;
    860   1.1        pk 	volatile struct bt_regs *bt;
    861   1.1        pk 
    862   1.1        pk 	/* hide the cursor, just in case */
    863   1.1        pk 	sc->sc_thc->thc_cursxy = (THC_CURSOFF << 16) | THC_CURSOFF;
    864   1.1        pk 
    865   1.1        pk 	/* turn off frobs in transform engine (makes X11 work) */
    866   1.1        pk 	tec = sc->sc_tec;
    867   1.1        pk 	tec->tec_mv = 0;
    868   1.1        pk 	tec->tec_clip = 0;
    869   1.1        pk 	tec->tec_vdc = 0;
    870   1.1        pk 
    871   1.1        pk 	/* take care of hardware bugs in old revisions */
    872   1.1        pk 	if (sc->sc_fhcrev < 5) {
    873   1.1        pk 		/*
    874  1.17       wiz 		 * Keep current resolution; set CPU to 68020, set test
    875   1.1        pk 		 * window (size 1Kx1K), and for rev 1, disable dest cache.
    876   1.1        pk 		 */
    877   1.1        pk 		fhc = (*sc->sc_fhc & FHC_RES_MASK) | FHC_CPU_68020 |
    878   1.1        pk 		    FHC_TEST |
    879   1.1        pk 		    (11 << FHC_TESTX_SHIFT) | (11 << FHC_TESTY_SHIFT);
    880   1.1        pk 		if (sc->sc_fhcrev < 2)
    881   1.1        pk 			fhc |= FHC_DST_DISABLE;
    882   1.1        pk 		*sc->sc_fhc = fhc;
    883   1.1        pk 	}
    884   1.1        pk 
    885   1.1        pk 	/* Enable cursor in Brooktree DAC. */
    886   1.1        pk 	bt = sc->sc_bt;
    887   1.1        pk 	bt->bt_addr = 0x06 << 24;
    888   1.1        pk 	bt->bt_ctrl |= 0x03 << 24;
    889   1.1        pk }
    890   1.1        pk 
    891   1.1        pk static void
    892   1.1        pk cg6_setcursor(sc)
    893   1.1        pk 	struct cgsix_softc *sc;
    894   1.1        pk {
    895   1.1        pk 
    896   1.1        pk 	/* we need to subtract the hot-spot value here */
    897   1.1        pk #define COORD(f) (sc->sc_cursor.cc_pos.f - sc->sc_cursor.cc_hot.f)
    898   1.1        pk 	sc->sc_thc->thc_cursxy = sc->sc_cursor.cc_enable ?
    899   1.1        pk 	    ((COORD(x) << 16) | (COORD(y) & 0xffff)) :
    900   1.1        pk 	    (THC_CURSOFF << 16) | THC_CURSOFF;
    901   1.1        pk #undef COORD
    902   1.1        pk }
    903   1.1        pk 
    904   1.1        pk static void
    905   1.1        pk cg6_loadcursor(sc)
    906   1.1        pk 	struct cgsix_softc *sc;
    907   1.1        pk {
    908   1.1        pk 	volatile struct cg6_thc *thc;
    909   1.1        pk 	u_int edgemask, m;
    910   1.1        pk 	int i;
    911   1.1        pk 
    912   1.1        pk 	/*
    913   1.1        pk 	 * Keep the top size.x bits.  Here we *throw out* the top
    914   1.1        pk 	 * size.x bits from an all-one-bits word, introducing zeros in
    915   1.1        pk 	 * the top size.x bits, then invert all the bits to get what
    916   1.1        pk 	 * we really wanted as our mask.  But this fails if size.x is
    917   1.1        pk 	 * 32---a sparc uses only the low 5 bits of the shift count---
    918   1.1        pk 	 * so we have to special case that.
    919   1.1        pk 	 */
    920   1.1        pk 	edgemask = ~0;
    921   1.1        pk 	if (sc->sc_cursor.cc_size.x < 32)
    922   1.1        pk 		edgemask = ~(edgemask >> sc->sc_cursor.cc_size.x);
    923   1.1        pk 	thc = sc->sc_thc;
    924   1.1        pk 	for (i = 0; i < 32; i++) {
    925   1.1        pk 		m = sc->sc_cursor.cc_bits[0][i] & edgemask;
    926   1.1        pk 		thc->thc_cursmask[i] = m;
    927   1.1        pk 		thc->thc_cursbits[i] = m & sc->sc_cursor.cc_bits[1][i];
    928   1.1        pk 	}
    929   1.1        pk }
    930   1.1        pk 
    931   1.1        pk /*
    932   1.1        pk  * Load a subset of the current (new) colormap into the color DAC.
    933   1.1        pk  */
    934   1.1        pk static void
    935   1.1        pk cg6_loadcmap(sc, start, ncolors)
    936   1.1        pk 	struct cgsix_softc *sc;
    937   1.1        pk 	int start, ncolors;
    938   1.1        pk {
    939   1.1        pk 	volatile struct bt_regs *bt;
    940   1.1        pk 	u_int *ip, i;
    941   1.1        pk 	int count;
    942   1.1        pk 
    943   1.1        pk 	ip = &sc->sc_cmap.cm_chip[BT_D4M3(start)];	/* start/4 * 3 */
    944   1.1        pk 	count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
    945   1.1        pk 	bt = sc->sc_bt;
    946   1.1        pk 	bt->bt_addr = BT_D4M4(start) << 24;
    947   1.1        pk 	while (--count >= 0) {
    948   1.1        pk 		i = *ip++;
    949   1.1        pk 		/* hardware that makes one want to pound boards with hammers */
    950   1.1        pk 		bt->bt_cmap = i;
    951   1.1        pk 		bt->bt_cmap = i << 8;
    952   1.1        pk 		bt->bt_cmap = i << 16;
    953   1.1        pk 		bt->bt_cmap = i << 24;
    954   1.1        pk 	}
    955   1.1        pk }
    956   1.1        pk 
    957   1.1        pk /*
    958   1.1        pk  * Load the cursor (overlay `foreground' and `background') colors.
    959   1.1        pk  */
    960   1.1        pk static void
    961   1.1        pk cg6_loadomap(sc)
    962   1.1        pk 	struct cgsix_softc *sc;
    963   1.1        pk {
    964   1.1        pk 	volatile struct bt_regs *bt;
    965   1.1        pk 	u_int i;
    966   1.1        pk 
    967   1.1        pk 	bt = sc->sc_bt;
    968   1.1        pk 	bt->bt_addr = 0x01 << 24;	/* set background color */
    969   1.1        pk 	i = sc->sc_cursor.cc_color.cm_chip[0];
    970   1.1        pk 	bt->bt_omap = i;		/* R */
    971   1.1        pk 	bt->bt_omap = i << 8;		/* G */
    972   1.1        pk 	bt->bt_omap = i << 16;		/* B */
    973   1.1        pk 
    974   1.1        pk 	bt->bt_addr = 0x03 << 24;	/* set foreground color */
    975   1.1        pk 	bt->bt_omap = i << 24;		/* R */
    976   1.1        pk 	i = sc->sc_cursor.cc_color.cm_chip[1];
    977   1.1        pk 	bt->bt_omap = i;		/* G */
    978   1.1        pk 	bt->bt_omap = i << 8;		/* B */
    979   1.1        pk }
    980   1.1        pk 
    981   1.1        pk static void
    982   1.1        pk cg6_unblank(dev)
    983   1.1        pk 	struct device *dev;
    984   1.1        pk {
    985   1.1        pk 	struct cgsix_softc *sc = (struct cgsix_softc *)dev;
    986   1.1        pk 
    987   1.1        pk 	if (sc->sc_blanked) {
    988   1.1        pk 		sc->sc_blanked = 0;
    989   1.1        pk 		sc->sc_thc->thc_misc |= THC_MISC_VIDEN;
    990   1.1        pk 	}
    991   1.1        pk }
    992   1.1        pk 
    993   1.1        pk /* XXX the following should be moved to a "user interface" header */
    994   1.1        pk /*
    995   1.1        pk  * Base addresses at which users can mmap() the various pieces of a cg6.
    996   1.1        pk  * Note that although the Brooktree color registers do not occupy 8K,
    997   1.1        pk  * the X server dies if we do not allow it to map 8K there (it just maps
    998   1.1        pk  * from 0x70000000 forwards, as a contiguous chunk).
    999   1.1        pk  */
   1000   1.1        pk #define	CG6_USER_FBC	0x70000000
   1001   1.1        pk #define	CG6_USER_TEC	0x70001000
   1002   1.1        pk #define	CG6_USER_BTREGS	0x70002000
   1003   1.1        pk #define	CG6_USER_FHC	0x70004000
   1004   1.1        pk #define	CG6_USER_THC	0x70005000
   1005   1.1        pk #define	CG6_USER_ROM	0x70006000
   1006   1.1        pk #define	CG6_USER_RAM	0x70016000
   1007   1.1        pk #define	CG6_USER_DHC	0x80000000
   1008   1.1        pk 
   1009   1.1        pk struct mmo {
   1010   1.2       eeh 	u_long	mo_uaddr;	/* user (virtual) address */
   1011   1.2       eeh 	u_long	mo_size;	/* size, or 0 for video ram size */
   1012   1.2       eeh 	u_long	mo_physoff;	/* offset from sc_physadr */
   1013   1.1        pk };
   1014   1.1        pk 
   1015   1.1        pk /*
   1016   1.1        pk  * Return the address that would map the given device at the given
   1017   1.1        pk  * offset, allowing for the given protection, or return -1 for error.
   1018   1.1        pk  *
   1019   1.1        pk  * XXX	needs testing against `demanding' applications (e.g., aviator)
   1020   1.1        pk  */
   1021   1.1        pk paddr_t
   1022   1.1        pk cgsixmmap(dev, off, prot)
   1023   1.1        pk 	dev_t dev;
   1024   1.1        pk 	off_t off;
   1025   1.1        pk 	int prot;
   1026   1.1        pk {
   1027   1.1        pk 	struct cgsix_softc *sc = cgsix_cd.cd_devs[minor(dev)];
   1028   1.1        pk 	struct mmo *mo;
   1029   1.1        pk 	u_int u, sz;
   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.1        pk 		sz = mo->mo_size ? mo->mo_size : sc->sc_fb.fb_type.fb_size;
   1059   1.1        pk 		if (u < sz) {
   1060   1.6       eeh 			return (bus_space_mmap(sc->sc_bustag,
   1061   1.6       eeh 				sc->sc_paddr, u+mo->mo_physoff,
   1062   1.6       eeh 				prot, BUS_SPACE_MAP_LINEAR));
   1063   1.1        pk 		}
   1064   1.1        pk 	}
   1065   1.1        pk 
   1066   1.1        pk #ifdef DEBUG
   1067   1.1        pk 	{
   1068  1.10   thorpej 	  struct proc *p = curlwp->l_proc;	/* XXX */
   1069   1.4       chs 	  log(LOG_NOTICE, "cgsixmmap(0x%llx) (%s[%d])\n",
   1070   1.4       chs 		(long long)off, p->p_comm, p->p_pid);
   1071   1.1        pk 	}
   1072   1.1        pk #endif
   1073   1.1        pk 	return (-1);	/* not a user-map offset */
   1074   1.1        pk }
   1075  1.18    martin 
   1076  1.18    martin /* dummies for multiple screen handling */
   1077  1.18    martin int
   1078  1.18    martin cgsix_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
   1079  1.18    martin 	void *v;
   1080  1.18    martin 	const struct wsscreen_descr *type;
   1081  1.18    martin 	void **cookiep;
   1082  1.18    martin 	int *curxp, *curyp;
   1083  1.18    martin 	long *attrp;
   1084  1.18    martin {
   1085  1.18    martin 	/*struct cg6_softc *sc = v;
   1086  1.18    martin 	struct rasops_info *ri = &sc->sc_dc->dc_ri;
   1087  1.18    martin 	long defattr;*/
   1088  1.18    martin 
   1089  1.18    martin 	return (ENOMEM);
   1090  1.18    martin }
   1091  1.18    martin 
   1092  1.18    martin void
   1093  1.18    martin cgsix_free_screen(v, cookie)
   1094  1.18    martin 	void *v;
   1095  1.18    martin 	void *cookie;
   1096  1.18    martin {
   1097  1.18    martin 	/*struct cg6_softc *sc = v;*/
   1098  1.18    martin }
   1099  1.18    martin 
   1100  1.18    martin int
   1101  1.18    martin cgsix_show_screen(v, cookie, waitok, cb, cbarg)
   1102  1.18    martin 	void *v;
   1103  1.18    martin 	void *cookie;
   1104  1.18    martin 	int waitok;
   1105  1.18    martin 	void (*cb) __P((void *, int, int));
   1106  1.18    martin 	void *cbarg;
   1107  1.18    martin {
   1108  1.18    martin 
   1109  1.18    martin 	return (0);
   1110  1.18    martin }
   1111  1.18    martin 
   1112  1.18    martin int
   1113  1.18    martin cgsix_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
   1114  1.18    martin {
   1115  1.18    martin 	/* we'll probably need to add more stuff here */
   1116  1.18    martin 	struct cgsix_softc *sc = v;
   1117  1.18    martin 	struct wsdisplay_fbinfo *wdf;
   1118  1.18    martin 	struct rasops_info *ri = &sc->sc_fb.fb_rinfo;
   1119  1.18    martin #ifdef CGSIX_DEBUG
   1120  1.18    martin 	printf("cgsix_ioctl(%ld)\n",cmd);
   1121  1.18    martin #endif
   1122  1.18    martin 	switch (cmd) {
   1123  1.18    martin 		case WSDISPLAYIO_GTYPE:
   1124  1.18    martin 			*(u_int *)data = WSDISPLAY_TYPE_SUNTCX;
   1125  1.18    martin 			return 0;
   1126  1.18    martin 		case WSDISPLAYIO_GINFO:
   1127  1.18    martin 			wdf = (void *)data;
   1128  1.18    martin 			wdf->height = ri->ri_height;
   1129  1.18    martin 			wdf->width = ri->ri_width;
   1130  1.18    martin 			wdf->depth = ri->ri_depth;
   1131  1.18    martin 			wdf->cmsize = 256;
   1132  1.18    martin 			return 0;
   1133  1.19     perry 
   1134  1.18    martin 		case WSDISPLAYIO_GETCMAP:
   1135  1.18    martin 			return cgsix_getcmap(sc, (struct wsdisplay_cmap *)data);
   1136  1.18    martin 		case WSDISPLAYIO_PUTCMAP:
   1137  1.18    martin 			return cgsix_putcmap(sc, (struct wsdisplay_cmap *)data);
   1138  1.19     perry 
   1139  1.18    martin #ifdef notyet
   1140  1.18    martin 		case WSDISPLAYIO_SMODE:
   1141  1.18    martin 			{
   1142  1.18    martin 				int new_mode=*(int*)data;
   1143  1.18    martin 				if(new_mode!=sc->sc_mode)
   1144  1.18    martin 				{
   1145  1.18    martin 					sc->sc_mode=new_mode;
   1146  1.18    martin 					if(new_mode==WSDISPLAYIO_MODE_EMUL)
   1147  1.18    martin 					{
   1148  1.19     perry 						/* we'll probably want to reset the console into a known state here
   1149  1.19     perry 						   just in case the Xserver crashed or didn't properly clean up after
   1150  1.18    martin 						   itself for whetever reason */
   1151  1.18    martin 					}
   1152  1.18    martin 				}
   1153  1.18    martin 			}
   1154  1.18    martin #endif
   1155  1.18    martin 	}
   1156  1.18    martin 	return EPASSTHROUGH;
   1157  1.18    martin }
   1158  1.18    martin 
   1159  1.18    martin paddr_t
   1160  1.18    martin cgsix_mmap(void *v, off_t offset, int prot)
   1161  1.18    martin {
   1162  1.18    martin 	struct cgsix_softc *sc = v;
   1163  1.18    martin 	/* how do I get the real RAM size? */
   1164  1.19     perry 	int ramsize=sc->sc_fb.fb_type.fb_height * sc->sc_fb.fb_linebytes;
   1165  1.18    martin 	if(offset<ramsize) {
   1166  1.18    martin 		return bus_space_mmap(sc->sc_bustag,sc->sc_paddr,CGSIX_RAM_OFFSET+offset,prot,BUS_SPACE_MAP_LINEAR);
   1167  1.18    martin 	}
   1168  1.18    martin 	/* I'm not at all sure this is the right thing to do */
   1169  1.18    martin 	return cgsixmmap(0,offset,prot); /* assume we're minor dev 0 for now */
   1170  1.18    martin }
   1171  1.18    martin 
   1172  1.19     perry int
   1173  1.18    martin cgsix_putcmap(struct cgsix_softc *sc, struct wsdisplay_cmap *cm)
   1174  1.18    martin {
   1175  1.18    martin 	u_int index = cm->index;
   1176  1.18    martin 	u_int count = cm->count;
   1177  1.18    martin 	int error,i;
   1178  1.18    martin 
   1179  1.18    martin 	if (index >= 256 || count > 256 || index + count > 256)
   1180  1.18    martin 		return EINVAL;
   1181  1.18    martin 
   1182  1.18    martin 	for(i=0;i<count;i++)
   1183  1.18    martin 	{
   1184  1.18    martin 		error = copyin(&cm->red[i], &sc->sc_cmap.cm_map[index+i][0], 1);
   1185  1.18    martin 		if (error)
   1186  1.18    martin 			return error;
   1187  1.18    martin 		error = copyin(&cm->green[i], &sc->sc_cmap.cm_map[index+i][1], 1);
   1188  1.18    martin 		if (error)
   1189  1.18    martin 			return error;
   1190  1.18    martin 		error = copyin(&cm->blue[i], &sc->sc_cmap.cm_map[index+i][2], 1);
   1191  1.18    martin 		if (error)
   1192  1.18    martin 			return error;
   1193  1.18    martin 	}
   1194  1.18    martin 	cg6_loadcmap(sc,index,count);
   1195  1.19     perry 
   1196  1.18    martin 	return 0;
   1197  1.18    martin }
   1198  1.18    martin 
   1199  1.18    martin int cgsix_getcmap(struct cgsix_softc *sc, struct wsdisplay_cmap *cm)
   1200  1.18    martin {
   1201  1.18    martin 	u_int index = cm->index;
   1202  1.18    martin 	u_int count = cm->count;
   1203  1.18    martin 	int error,i;
   1204  1.18    martin 
   1205  1.18    martin 	if (index >= 256 || count > 256 || index + count > 256)
   1206  1.18    martin 		return EINVAL;
   1207  1.18    martin 
   1208  1.18    martin 	for(i=0;i<count;i++)
   1209  1.18    martin 	{
   1210  1.18    martin 		error = copyout(&sc->sc_cmap.cm_map[index+i][0],   &cm->red[i],1);
   1211  1.18    martin 		if (error)
   1212  1.18    martin 			return error;
   1213  1.18    martin 		error = copyout(&sc->sc_cmap.cm_map[index+i][1],   &cm->green[i],1);
   1214  1.18    martin 		if (error)
   1215  1.18    martin 			return error;
   1216  1.18    martin 		error = copyout(&sc->sc_cmap.cm_map[index+i][2],   &cm->blue[i],1);
   1217  1.18    martin 		if (error)
   1218  1.18    martin 			return error;
   1219  1.18    martin 	}
   1220  1.19     perry 
   1221  1.18    martin 	return 0;
   1222  1.18    martin }
   1223