Home | History | Annotate | Line # | Download | only in dev
cg2.c revision 1.16.4.2
      1  1.16.4.2  nathanw /*	$NetBSD: cg2.c,v 1.16.4.2 2002/08/13 02:18:59 nathanw Exp $	*/
      2  1.16.4.2  nathanw 
      3  1.16.4.2  nathanw /*
      4  1.16.4.2  nathanw  * Copyright (c) 1992, 1993
      5  1.16.4.2  nathanw  *	The Regents of the University of California.  All rights reserved.
      6  1.16.4.2  nathanw  *
      7  1.16.4.2  nathanw  * This software was developed by the Computer Systems Engineering group
      8  1.16.4.2  nathanw  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  1.16.4.2  nathanw  * contributed to Berkeley.
     10  1.16.4.2  nathanw  *
     11  1.16.4.2  nathanw  * All advertising materials mentioning features or use of this software
     12  1.16.4.2  nathanw  * must display the following acknowledgement:
     13  1.16.4.2  nathanw  *	This product includes software developed by the University of
     14  1.16.4.2  nathanw  *	California, Lawrence Berkeley Laboratory.
     15  1.16.4.2  nathanw  *
     16  1.16.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
     17  1.16.4.2  nathanw  * modification, are permitted provided that the following conditions
     18  1.16.4.2  nathanw  * are met:
     19  1.16.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     20  1.16.4.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     21  1.16.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     22  1.16.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     23  1.16.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     24  1.16.4.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     25  1.16.4.2  nathanw  *    must display the following acknowledgement:
     26  1.16.4.2  nathanw  *	This product includes software developed by the University of
     27  1.16.4.2  nathanw  *	California, Berkeley and its contributors.
     28  1.16.4.2  nathanw  * 4. Neither the name of the University nor the names of its contributors
     29  1.16.4.2  nathanw  *    may be used to endorse or promote products derived from this software
     30  1.16.4.2  nathanw  *    without specific prior written permission.
     31  1.16.4.2  nathanw  *
     32  1.16.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33  1.16.4.2  nathanw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  1.16.4.2  nathanw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  1.16.4.2  nathanw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36  1.16.4.2  nathanw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  1.16.4.2  nathanw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  1.16.4.2  nathanw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  1.16.4.2  nathanw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  1.16.4.2  nathanw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  1.16.4.2  nathanw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  1.16.4.2  nathanw  * SUCH DAMAGE.
     43  1.16.4.2  nathanw  *
     44  1.16.4.2  nathanw  *	from: @(#)cgthree.c	8.2 (Berkeley) 10/30/93
     45  1.16.4.2  nathanw  */
     46  1.16.4.2  nathanw 
     47  1.16.4.2  nathanw /*
     48  1.16.4.2  nathanw  * color display (cg2) driver.
     49  1.16.4.2  nathanw  *
     50  1.16.4.2  nathanw  * Does not handle interrupts, even though they can occur.
     51  1.16.4.2  nathanw  *
     52  1.16.4.2  nathanw  * XXX should defer colormap updates to vertical retrace interrupts
     53  1.16.4.2  nathanw  */
     54  1.16.4.2  nathanw 
     55  1.16.4.2  nathanw #include <sys/param.h>
     56  1.16.4.2  nathanw #include <sys/systm.h>
     57  1.16.4.2  nathanw #include <sys/conf.h>
     58  1.16.4.2  nathanw #include <sys/device.h>
     59  1.16.4.2  nathanw #include <sys/ioctl.h>
     60  1.16.4.2  nathanw #include <sys/malloc.h>
     61  1.16.4.2  nathanw #include <sys/mman.h>
     62  1.16.4.2  nathanw #include <sys/proc.h>
     63  1.16.4.2  nathanw #include <sys/tty.h>
     64  1.16.4.2  nathanw 
     65  1.16.4.2  nathanw #include <uvm/uvm_extern.h>
     66  1.16.4.2  nathanw 
     67  1.16.4.2  nathanw #include <dev/sun/fbio.h>
     68  1.16.4.2  nathanw #include <machine/autoconf.h>
     69  1.16.4.2  nathanw #include <machine/pmap.h>
     70  1.16.4.2  nathanw #include <machine/cg2reg.h>
     71  1.16.4.2  nathanw 
     72  1.16.4.2  nathanw #include "fbvar.h"
     73  1.16.4.2  nathanw 
     74  1.16.4.2  nathanw cdev_decl(cg2);
     75  1.16.4.2  nathanw 
     76  1.16.4.2  nathanw #define	CMSIZE 256
     77  1.16.4.2  nathanw 
     78  1.16.4.2  nathanw /* offset to and size of mapped part of frame buffer */
     79  1.16.4.2  nathanw #define PLANEMAP_SIZE		0x100000
     80  1.16.4.2  nathanw #define PIXELMAP_SIZE		0x100000
     81  1.16.4.2  nathanw #define ROWOPMAP_SIZE		0x100000
     82  1.16.4.2  nathanw 
     83  1.16.4.2  nathanw #define	CTLREGS_OFF 		0x300000
     84  1.16.4.2  nathanw #define	CTLREGS_SIZE		 0x10600
     85  1.16.4.2  nathanw 
     86  1.16.4.2  nathanw #define	CG2_MAPPED_OFFSET	(PLANEMAP_SIZE + PIXELMAP_SIZE)
     87  1.16.4.2  nathanw #define	CG2_MAPPED_SIZE 	(CTLREGS_OFF + CTLREGS_SIZE)
     88  1.16.4.2  nathanw 
     89  1.16.4.2  nathanw /* per-display variables */
     90  1.16.4.2  nathanw struct cg2_softc {
     91  1.16.4.2  nathanw 	struct	device sc_dev;		/* base device */
     92  1.16.4.2  nathanw 	struct	fbdevice sc_fb;		/* frame buffer device */
     93  1.16.4.2  nathanw 	int 	sc_phys;		/* display RAM (phys addr) */
     94  1.16.4.2  nathanw 	int 	sc_pmtype;		/* pmap type bits */
     95  1.16.4.2  nathanw 	struct	cg2fb *sc_ctlreg;	/* control registers */
     96  1.16.4.2  nathanw };
     97  1.16.4.2  nathanw 
     98  1.16.4.2  nathanw /* autoconfiguration driver */
     99  1.16.4.2  nathanw static void	cg2attach __P((struct device *, struct device *, void *));
    100  1.16.4.2  nathanw static int	cg2match __P((struct device *, struct cfdata *, void *));
    101  1.16.4.2  nathanw 
    102  1.16.4.2  nathanw struct cfattach cgtwo_ca = {
    103  1.16.4.2  nathanw 	sizeof(struct cg2_softc), cg2match, cg2attach
    104  1.16.4.2  nathanw };
    105  1.16.4.2  nathanw 
    106  1.16.4.2  nathanw extern struct cfdriver cgtwo_cd;
    107  1.16.4.2  nathanw 
    108  1.16.4.2  nathanw static int  cg2gattr __P((struct fbdevice *,  void *));
    109  1.16.4.2  nathanw static int  cg2gvideo __P((struct fbdevice *, void *));
    110  1.16.4.2  nathanw static int	cg2svideo __P((struct fbdevice *, void *));
    111  1.16.4.2  nathanw static int	cg2getcmap __P((struct fbdevice *, void *));
    112  1.16.4.2  nathanw static int	cg2putcmap __P((struct fbdevice *, void *));
    113  1.16.4.2  nathanw 
    114  1.16.4.2  nathanw static struct fbdriver cg2fbdriver = {
    115  1.16.4.2  nathanw 	cg2open, cg2close, cg2mmap, cg2gattr,
    116  1.16.4.2  nathanw 	cg2gvideo, cg2svideo,
    117  1.16.4.2  nathanw 	cg2getcmap, cg2putcmap };
    118  1.16.4.2  nathanw 
    119  1.16.4.2  nathanw static int cg2intr __P((void*));
    120  1.16.4.2  nathanw 
    121  1.16.4.2  nathanw /*
    122  1.16.4.2  nathanw  * Match a cg2.
    123  1.16.4.2  nathanw  */
    124  1.16.4.2  nathanw static int
    125  1.16.4.2  nathanw cg2match(parent, cf, aux)
    126  1.16.4.2  nathanw 	struct device *parent;
    127  1.16.4.2  nathanw 	struct cfdata *cf;
    128  1.16.4.2  nathanw 	void *aux;
    129  1.16.4.2  nathanw {
    130  1.16.4.2  nathanw 	struct confargs *ca = aux;
    131  1.16.4.2  nathanw 	int probe_addr;
    132  1.16.4.2  nathanw 
    133  1.16.4.2  nathanw 	/* No default VME address. */
    134  1.16.4.2  nathanw 	if (ca->ca_paddr == -1)
    135  1.16.4.2  nathanw 		return (0);
    136  1.16.4.2  nathanw 
    137  1.16.4.2  nathanw 	/* Make sure something is there... */
    138  1.16.4.2  nathanw 	probe_addr = ca->ca_paddr + CTLREGS_OFF;
    139  1.16.4.2  nathanw 	if (bus_peek(ca->ca_bustype, probe_addr, 1) == -1)
    140  1.16.4.2  nathanw 		return (0);
    141  1.16.4.2  nathanw 
    142  1.16.4.2  nathanw 	/* XXX: look at the ID reg? */
    143  1.16.4.2  nathanw 	/* printf("cg2: id=0x%x\n", x); */
    144  1.16.4.2  nathanw 
    145  1.16.4.2  nathanw 	/* Default interrupt priority. */
    146  1.16.4.2  nathanw 	if (ca->ca_intpri == -1)
    147  1.16.4.2  nathanw 		ca->ca_intpri = 4;
    148  1.16.4.2  nathanw 
    149  1.16.4.2  nathanw 	return (1);
    150  1.16.4.2  nathanw }
    151  1.16.4.2  nathanw 
    152  1.16.4.2  nathanw /*
    153  1.16.4.2  nathanw  * Attach a display.  We need to notice if it is the console, too.
    154  1.16.4.2  nathanw  */
    155  1.16.4.2  nathanw static void
    156  1.16.4.2  nathanw cg2attach(parent, self, args)
    157  1.16.4.2  nathanw 	struct device *parent, *self;
    158  1.16.4.2  nathanw 	void *args;
    159  1.16.4.2  nathanw {
    160  1.16.4.2  nathanw 	struct cg2_softc *sc = (struct cg2_softc *)self;
    161  1.16.4.2  nathanw 	struct fbdevice *fb = &sc->sc_fb;
    162  1.16.4.2  nathanw 	struct confargs *ca = args;
    163  1.16.4.2  nathanw 	struct fbtype *fbt;
    164  1.16.4.2  nathanw 
    165  1.16.4.2  nathanw 	sc->sc_phys = ca->ca_paddr;
    166  1.16.4.2  nathanw 	sc->sc_pmtype = PMAP_NC | PMAP_VME16;
    167  1.16.4.2  nathanw 
    168  1.16.4.2  nathanw 	sc->sc_ctlreg = (struct cg2fb *) bus_mapin(ca->ca_bustype,
    169  1.16.4.2  nathanw 			ca->ca_paddr + CTLREGS_OFF, CTLREGS_SIZE);
    170  1.16.4.2  nathanw 
    171  1.16.4.2  nathanw 	isr_add_vectored(cg2intr, (void*)sc,
    172  1.16.4.2  nathanw 					 ca->ca_intpri, ca->ca_intvec);
    173  1.16.4.2  nathanw 
    174  1.16.4.2  nathanw 	/*
    175  1.16.4.2  nathanw 	 * XXX - Initialize?  Determine type?
    176  1.16.4.2  nathanw 	 */
    177  1.16.4.2  nathanw 	sc->sc_ctlreg->intrptvec.reg = ca->ca_intvec;
    178  1.16.4.2  nathanw 	sc->sc_ctlreg->status.word = 1;
    179  1.16.4.2  nathanw 
    180  1.16.4.2  nathanw 	fb->fb_driver = &cg2fbdriver;
    181  1.16.4.2  nathanw 	fb->fb_private = sc;
    182  1.16.4.2  nathanw 	fb->fb_name = sc->sc_dev.dv_xname;
    183  1.16.4.2  nathanw 
    184  1.16.4.2  nathanw 	fbt = &fb->fb_fbtype;
    185  1.16.4.2  nathanw 	fbt->fb_type = FBTYPE_SUN2COLOR;
    186  1.16.4.2  nathanw 	fbt->fb_depth = 8;
    187  1.16.4.2  nathanw 	fbt->fb_cmsize = CMSIZE;
    188  1.16.4.2  nathanw 
    189  1.16.4.2  nathanw 	fbt->fb_width = 1152;
    190  1.16.4.2  nathanw 	fbt->fb_height = 900;
    191  1.16.4.2  nathanw 	fbt->fb_size = CG2_MAPPED_SIZE;
    192  1.16.4.2  nathanw 
    193  1.16.4.2  nathanw 	printf(" (%dx%d)\n", fbt->fb_width, fbt->fb_height);
    194  1.16.4.2  nathanw 	fb_attach(fb, 2);
    195  1.16.4.2  nathanw }
    196  1.16.4.2  nathanw 
    197  1.16.4.2  nathanw int
    198  1.16.4.2  nathanw cg2open(dev, flags, mode, p)
    199  1.16.4.2  nathanw 	dev_t dev;
    200  1.16.4.2  nathanw 	int flags, mode;
    201  1.16.4.2  nathanw 	struct proc *p;
    202  1.16.4.2  nathanw {
    203  1.16.4.2  nathanw 	int unit = minor(dev);
    204  1.16.4.2  nathanw 
    205  1.16.4.2  nathanw 	if (unit >= cgtwo_cd.cd_ndevs || cgtwo_cd.cd_devs[unit] == NULL)
    206  1.16.4.2  nathanw 		return (ENXIO);
    207  1.16.4.2  nathanw 	return (0);
    208  1.16.4.2  nathanw }
    209  1.16.4.2  nathanw 
    210  1.16.4.2  nathanw int
    211  1.16.4.2  nathanw cg2close(dev, flags, mode, p)
    212  1.16.4.2  nathanw 	dev_t dev;
    213  1.16.4.2  nathanw 	int flags, mode;
    214  1.16.4.2  nathanw 	struct proc *p;
    215  1.16.4.2  nathanw {
    216  1.16.4.2  nathanw 
    217  1.16.4.2  nathanw 	return (0);
    218  1.16.4.2  nathanw }
    219  1.16.4.2  nathanw 
    220  1.16.4.2  nathanw int
    221  1.16.4.2  nathanw cg2ioctl(dev, cmd, data, flags, p)
    222  1.16.4.2  nathanw 	dev_t dev;
    223  1.16.4.2  nathanw 	u_long cmd;
    224  1.16.4.2  nathanw 	caddr_t data;
    225  1.16.4.2  nathanw 	int flags;
    226  1.16.4.2  nathanw 	struct proc *p;
    227  1.16.4.2  nathanw {
    228  1.16.4.2  nathanw 	struct cg2_softc *sc = cgtwo_cd.cd_devs[minor(dev)];
    229  1.16.4.2  nathanw 
    230  1.16.4.2  nathanw 	return (fbioctlfb(&sc->sc_fb, cmd, data));
    231  1.16.4.2  nathanw }
    232  1.16.4.2  nathanw 
    233  1.16.4.2  nathanw /*
    234  1.16.4.2  nathanw  * Return the address that would map the given device at the given
    235  1.16.4.2  nathanw  * offset, allowing for the given protection, or return -1 for error.
    236  1.16.4.2  nathanw  */
    237  1.16.4.2  nathanw paddr_t
    238  1.16.4.2  nathanw cg2mmap(dev, off, prot)
    239  1.16.4.2  nathanw 	dev_t dev;
    240  1.16.4.2  nathanw 	off_t off;
    241  1.16.4.2  nathanw 	int prot;
    242  1.16.4.2  nathanw {
    243  1.16.4.2  nathanw 	struct cg2_softc *sc = cgtwo_cd.cd_devs[minor(dev)];
    244  1.16.4.2  nathanw 
    245  1.16.4.2  nathanw 	if (off & PGOFSET)
    246  1.16.4.2  nathanw 		panic("cg2mmap");
    247  1.16.4.2  nathanw 
    248  1.16.4.2  nathanw 	if (off >= CG2_MAPPED_SIZE)
    249  1.16.4.2  nathanw 		return (-1);
    250  1.16.4.2  nathanw 
    251  1.16.4.2  nathanw 	/*
    252  1.16.4.2  nathanw 	 * I turned on PMAP_NC here to disable the cache as I was
    253  1.16.4.2  nathanw 	 * getting horribly broken behaviour with it on.
    254  1.16.4.2  nathanw 	 */
    255  1.16.4.2  nathanw 	return ((sc->sc_phys + off) | sc->sc_pmtype);
    256  1.16.4.2  nathanw }
    257  1.16.4.2  nathanw 
    258  1.16.4.2  nathanw /*
    259  1.16.4.2  nathanw  * Internal ioctl functions.
    260  1.16.4.2  nathanw  */
    261  1.16.4.2  nathanw 
    262  1.16.4.2  nathanw /* FBIOGATTR: */
    263  1.16.4.2  nathanw static int  cg2gattr(fb, data)
    264  1.16.4.2  nathanw 	struct fbdevice *fb;
    265  1.16.4.2  nathanw 	void *data;
    266  1.16.4.2  nathanw {
    267  1.16.4.2  nathanw 	struct fbgattr *fba = data;
    268  1.16.4.2  nathanw 
    269  1.16.4.2  nathanw 	fba->real_type = fb->fb_fbtype.fb_type;
    270  1.16.4.2  nathanw 	fba->owner = 0;		/* XXX - TIOCCONS stuff? */
    271  1.16.4.2  nathanw 	fba->fbtype = fb->fb_fbtype;
    272  1.16.4.2  nathanw 	fba->sattr.flags = 0;
    273  1.16.4.2  nathanw 	fba->sattr.emu_type = fb->fb_fbtype.fb_type;
    274  1.16.4.2  nathanw 	fba->sattr.dev_specific[0] = -1;
    275  1.16.4.2  nathanw 	fba->emu_types[0] = fb->fb_fbtype.fb_type;
    276  1.16.4.2  nathanw 	fba->emu_types[1] = -1;
    277  1.16.4.2  nathanw 	return (0);
    278  1.16.4.2  nathanw }
    279  1.16.4.2  nathanw 
    280  1.16.4.2  nathanw /* FBIOGVIDEO: */
    281  1.16.4.2  nathanw static int  cg2gvideo(fb, data)
    282  1.16.4.2  nathanw 	struct fbdevice *fb;
    283  1.16.4.2  nathanw 	void *data;
    284  1.16.4.2  nathanw {
    285  1.16.4.2  nathanw 	int *on = data;
    286  1.16.4.2  nathanw 	struct cg2_softc *sc = fb->fb_private;
    287  1.16.4.2  nathanw 
    288  1.16.4.2  nathanw 	*on = sc->sc_ctlreg->status.reg.video_enab;
    289  1.16.4.2  nathanw 	return (0);
    290  1.16.4.2  nathanw }
    291  1.16.4.2  nathanw 
    292  1.16.4.2  nathanw /* FBIOSVIDEO: */
    293  1.16.4.2  nathanw static int cg2svideo(fb, data)
    294  1.16.4.2  nathanw 	struct fbdevice *fb;
    295  1.16.4.2  nathanw 	void *data;
    296  1.16.4.2  nathanw {
    297  1.16.4.2  nathanw 	int *on = data;
    298  1.16.4.2  nathanw 	struct cg2_softc *sc = fb->fb_private;
    299  1.16.4.2  nathanw 
    300  1.16.4.2  nathanw 	sc->sc_ctlreg->status.reg.video_enab = (*on) & 1;
    301  1.16.4.2  nathanw 
    302  1.16.4.2  nathanw 	return (0);
    303  1.16.4.2  nathanw }
    304  1.16.4.2  nathanw 
    305  1.16.4.2  nathanw /* FBIOGETCMAP: */
    306  1.16.4.2  nathanw static int cg2getcmap(fb, data)
    307  1.16.4.2  nathanw 	struct fbdevice *fb;
    308  1.16.4.2  nathanw 	void *data;
    309  1.16.4.2  nathanw {
    310  1.16.4.2  nathanw 	struct fbcmap *cmap = data;
    311  1.16.4.2  nathanw 	struct cg2_softc *sc = fb->fb_private;
    312  1.16.4.2  nathanw 	u_char red[CMSIZE], green[CMSIZE], blue[CMSIZE];
    313  1.16.4.2  nathanw 	int error, start, count, ecount;
    314  1.16.4.2  nathanw 	u_int i;
    315  1.16.4.2  nathanw 	u_short *p;
    316  1.16.4.2  nathanw 
    317  1.16.4.2  nathanw 	start = cmap->index;
    318  1.16.4.2  nathanw 	count = cmap->count;
    319  1.16.4.2  nathanw 	ecount = start + count;
    320  1.16.4.2  nathanw 	if (start >= CMSIZE || count > CMSIZE - start)
    321  1.16.4.2  nathanw 		return (EINVAL);
    322  1.16.4.2  nathanw 
    323  1.16.4.2  nathanw 	/* XXX - Wait for retrace? */
    324  1.16.4.2  nathanw 
    325  1.16.4.2  nathanw 	/* Copy hardware to local arrays. */
    326  1.16.4.2  nathanw 	p = &sc->sc_ctlreg->redmap[start];
    327  1.16.4.2  nathanw 	for (i = start; i < ecount; i++)
    328  1.16.4.2  nathanw 		red[i] = *p++;
    329  1.16.4.2  nathanw 	p = &sc->sc_ctlreg->greenmap[start];
    330  1.16.4.2  nathanw 	for (i = start; i < ecount; i++)
    331  1.16.4.2  nathanw 		green[i] = *p++;
    332  1.16.4.2  nathanw 	p = &sc->sc_ctlreg->bluemap[start];
    333  1.16.4.2  nathanw 	for (i = start; i < ecount; i++)
    334  1.16.4.2  nathanw 		blue[i] = *p++;
    335  1.16.4.2  nathanw 
    336  1.16.4.2  nathanw 	/* Copy local arrays to user space. */
    337  1.16.4.2  nathanw 	if ((error = copyout(red + start, cmap->red, count)) != 0)
    338  1.16.4.2  nathanw 		return (error);
    339  1.16.4.2  nathanw 	if ((error = copyout(green + start, cmap->green, count)) != 0)
    340  1.16.4.2  nathanw 		return (error);
    341  1.16.4.2  nathanw 	if ((error = copyout(blue + start, cmap->blue, count)) != 0)
    342  1.16.4.2  nathanw 		return (error);
    343  1.16.4.2  nathanw 
    344  1.16.4.2  nathanw 	return (0);
    345  1.16.4.2  nathanw }
    346  1.16.4.2  nathanw 
    347  1.16.4.2  nathanw /* FBIOPUTCMAP: */
    348  1.16.4.2  nathanw static int cg2putcmap(fb, data)
    349  1.16.4.2  nathanw 	struct fbdevice *fb;
    350  1.16.4.2  nathanw 	void *data;
    351  1.16.4.2  nathanw {
    352  1.16.4.2  nathanw 	struct fbcmap *cmap = data;
    353  1.16.4.2  nathanw 	struct cg2_softc *sc = fb->fb_private;
    354  1.16.4.2  nathanw 	u_char red[CMSIZE], green[CMSIZE], blue[CMSIZE];
    355  1.16.4.2  nathanw 	int error;
    356  1.16.4.2  nathanw 	u_int start, count, ecount;
    357  1.16.4.2  nathanw 	u_int i;
    358  1.16.4.2  nathanw 	u_short *p;
    359  1.16.4.2  nathanw 
    360  1.16.4.2  nathanw 	start = cmap->index;
    361  1.16.4.2  nathanw 	count = cmap->count;
    362  1.16.4.2  nathanw 	ecount = start + count;
    363  1.16.4.2  nathanw 	if (start >= CMSIZE || count > CMSIZE - start)
    364  1.16.4.2  nathanw 		return (EINVAL);
    365  1.16.4.2  nathanw 
    366  1.16.4.2  nathanw 	/* Copy from user space to local arrays. */
    367  1.16.4.2  nathanw 	if ((error = copyin(cmap->red, red + start, count)) != 0)
    368  1.16.4.2  nathanw 		return (error);
    369  1.16.4.2  nathanw 	if ((error = copyin(cmap->green, green + start, count)) != 0)
    370  1.16.4.2  nathanw 		return (error);
    371  1.16.4.2  nathanw 	if ((error = copyin(cmap->blue, blue + start, count)) != 0)
    372  1.16.4.2  nathanw 		return (error);
    373  1.16.4.2  nathanw 
    374  1.16.4.2  nathanw 	/* XXX - Wait for retrace? */
    375  1.16.4.2  nathanw 
    376  1.16.4.2  nathanw 	/* Copy from local arrays to hardware. */
    377  1.16.4.2  nathanw 	p = &sc->sc_ctlreg->redmap[start];
    378  1.16.4.2  nathanw 	for (i = start; i < ecount; i++)
    379  1.16.4.2  nathanw 		*p++ = red[i];
    380  1.16.4.2  nathanw 	p = &sc->sc_ctlreg->greenmap[start];
    381  1.16.4.2  nathanw 	for (i = start; i < ecount; i++)
    382  1.16.4.2  nathanw 		*p++ = green[i];
    383  1.16.4.2  nathanw 	p = &sc->sc_ctlreg->bluemap[start];
    384  1.16.4.2  nathanw 	for (i = start; i < ecount; i++)
    385  1.16.4.2  nathanw 		*p++ = blue[i];
    386  1.16.4.2  nathanw 
    387  1.16.4.2  nathanw 	return (0);
    388  1.16.4.2  nathanw 
    389  1.16.4.2  nathanw }
    390  1.16.4.2  nathanw 
    391  1.16.4.2  nathanw static int
    392  1.16.4.2  nathanw cg2intr(vsc)
    393  1.16.4.2  nathanw 	void *vsc;
    394  1.16.4.2  nathanw {
    395  1.16.4.2  nathanw 	struct cg2_softc *sc = vsc;
    396  1.16.4.2  nathanw 
    397  1.16.4.2  nathanw 	/* XXX - Just disable interrupts for now. */
    398  1.16.4.2  nathanw 	sc->sc_ctlreg->status.reg.inten = 0;
    399  1.16.4.2  nathanw 
    400  1.16.4.2  nathanw 	printf("cg2intr\n");
    401  1.16.4.2  nathanw 	return (1);
    402  1.16.4.2  nathanw }
    403