Home | History | Annotate | Line # | Download | only in dev
cgtwo.c revision 1.35.6.3
      1  1.35.6.3  nathanw /*	$NetBSD: cgtwo.c,v 1.35.6.3 2002/09/17 21:17:41 nathanw Exp $ */
      2  1.35.6.2  nathanw 
      3  1.35.6.2  nathanw /*
      4  1.35.6.2  nathanw  * Copyright (c) 1992, 1993
      5  1.35.6.2  nathanw  *	The Regents of the University of California.  All rights reserved.
      6  1.35.6.2  nathanw  *
      7  1.35.6.2  nathanw  * This software was developed by the Computer Systems Engineering group
      8  1.35.6.2  nathanw  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  1.35.6.2  nathanw  * contributed to Berkeley.
     10  1.35.6.2  nathanw  *
     11  1.35.6.2  nathanw  * All advertising materials mentioning features or use of this software
     12  1.35.6.2  nathanw  * must display the following acknowledgement:
     13  1.35.6.2  nathanw  *	This product includes software developed by the University of
     14  1.35.6.2  nathanw  *	California, Lawrence Berkeley Laboratory.
     15  1.35.6.2  nathanw  *
     16  1.35.6.2  nathanw  * Redistribution and use in source and binary forms, with or without
     17  1.35.6.2  nathanw  * modification, are permitted provided that the following conditions
     18  1.35.6.2  nathanw  * are met:
     19  1.35.6.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     20  1.35.6.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     21  1.35.6.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     22  1.35.6.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     23  1.35.6.2  nathanw  *    documentation and/or other materials provided with the distribution.
     24  1.35.6.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     25  1.35.6.2  nathanw  *    must display the following acknowledgement:
     26  1.35.6.2  nathanw  *	This product includes software developed by the University of
     27  1.35.6.2  nathanw  *	California, Berkeley and its contributors.
     28  1.35.6.2  nathanw  * 4. Neither the name of the University nor the names of its contributors
     29  1.35.6.2  nathanw  *    may be used to endorse or promote products derived from this software
     30  1.35.6.2  nathanw  *    without specific prior written permission.
     31  1.35.6.2  nathanw  *
     32  1.35.6.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33  1.35.6.2  nathanw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  1.35.6.2  nathanw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  1.35.6.2  nathanw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36  1.35.6.2  nathanw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  1.35.6.2  nathanw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  1.35.6.2  nathanw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  1.35.6.2  nathanw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  1.35.6.2  nathanw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  1.35.6.2  nathanw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  1.35.6.2  nathanw  * SUCH DAMAGE.
     43  1.35.6.2  nathanw  *
     44  1.35.6.2  nathanw  *	from: @(#)cgthree.c	8.2 (Berkeley) 10/30/93
     45  1.35.6.2  nathanw  */
     46  1.35.6.2  nathanw 
     47  1.35.6.2  nathanw /*
     48  1.35.6.2  nathanw  * color display (cgtwo) driver.
     49  1.35.6.2  nathanw  *
     50  1.35.6.2  nathanw  * Does not handle interrupts, even though they can occur.
     51  1.35.6.2  nathanw  *
     52  1.35.6.2  nathanw  * XXX should defer colormap updates to vertical retrace interrupts
     53  1.35.6.2  nathanw  */
     54  1.35.6.2  nathanw 
     55  1.35.6.2  nathanw #include <sys/param.h>
     56  1.35.6.2  nathanw #include <sys/systm.h>
     57  1.35.6.2  nathanw #include <sys/buf.h>
     58  1.35.6.2  nathanw #include <sys/device.h>
     59  1.35.6.2  nathanw #include <sys/ioctl.h>
     60  1.35.6.2  nathanw #include <sys/malloc.h>
     61  1.35.6.2  nathanw #include <sys/mman.h>
     62  1.35.6.2  nathanw #include <sys/tty.h>
     63  1.35.6.2  nathanw #include <sys/conf.h>
     64  1.35.6.2  nathanw 
     65  1.35.6.2  nathanw #include <machine/autoconf.h>
     66  1.35.6.2  nathanw 
     67  1.35.6.2  nathanw #include <dev/sun/fbio.h>
     68  1.35.6.2  nathanw #include <dev/sun/fbvar.h>
     69  1.35.6.2  nathanw 
     70  1.35.6.2  nathanw #include <dev/vme/vmevar.h>
     71  1.35.6.2  nathanw 
     72  1.35.6.2  nathanw #include <machine/eeprom.h>
     73  1.35.6.2  nathanw #include <machine/cgtworeg.h>
     74  1.35.6.2  nathanw 
     75  1.35.6.2  nathanw 
     76  1.35.6.2  nathanw /* per-display variables */
     77  1.35.6.2  nathanw struct cgtwo_softc {
     78  1.35.6.2  nathanw 	struct	device sc_dev;		/* base device */
     79  1.35.6.2  nathanw 	struct	fbdevice sc_fb;		/* frame buffer device */
     80  1.35.6.2  nathanw 	vme_addr_t		sc_paddr;
     81  1.35.6.2  nathanw 	vme_chipset_tag_t	sc_ct;
     82  1.35.6.2  nathanw 	bus_space_tag_t		sc_bt;
     83  1.35.6.2  nathanw 	volatile struct cg2statusreg *sc_reg;	/* CG2 control registers */
     84  1.35.6.2  nathanw 	volatile u_short *sc_cmap;
     85  1.35.6.2  nathanw #define sc_redmap(sc)	((sc)->sc_cmap)
     86  1.35.6.2  nathanw #define sc_greenmap(sc)	((sc)->sc_cmap + CG2_CMSIZE)
     87  1.35.6.2  nathanw #define sc_bluemap(sc)	((sc)->sc_cmap + 2 * CG2_CMSIZE)
     88  1.35.6.2  nathanw };
     89  1.35.6.2  nathanw 
     90  1.35.6.2  nathanw /* autoconfiguration driver */
     91  1.35.6.2  nathanw static void	cgtwoattach __P((struct device *, struct device *, void *));
     92  1.35.6.2  nathanw static int	cgtwomatch __P((struct device *, struct cfdata *, void *));
     93  1.35.6.2  nathanw static void	cgtwounblank __P((struct device *));
     94  1.35.6.2  nathanw int		cgtwogetcmap __P((struct cgtwo_softc *, struct fbcmap *));
     95  1.35.6.2  nathanw int		cgtwoputcmap __P((struct cgtwo_softc *, struct fbcmap *));
     96  1.35.6.2  nathanw 
     97  1.35.6.2  nathanw struct cfattach cgtwo_ca = {
     98  1.35.6.2  nathanw 	sizeof(struct cgtwo_softc), cgtwomatch, cgtwoattach
     99  1.35.6.2  nathanw };
    100  1.35.6.2  nathanw 
    101  1.35.6.2  nathanw extern struct cfdriver cgtwo_cd;
    102  1.35.6.2  nathanw 
    103  1.35.6.3  nathanw dev_type_open(cgtwoopen);
    104  1.35.6.3  nathanw dev_type_ioctl(cgtwoioctl);
    105  1.35.6.3  nathanw dev_type_mmap(cgtwommap);
    106  1.35.6.3  nathanw 
    107  1.35.6.3  nathanw const struct cdevsw cgtwo_cdevsw = {
    108  1.35.6.3  nathanw 	cgtwoopen, nullclose, noread, nowrite, cgtwoioctl,
    109  1.35.6.3  nathanw 	nostop, notty, nopoll, cgtwommap,
    110  1.35.6.3  nathanw };
    111  1.35.6.3  nathanw 
    112  1.35.6.2  nathanw /* frame buffer generic driver */
    113  1.35.6.2  nathanw static struct fbdriver cgtwofbdriver = {
    114  1.35.6.3  nathanw 	cgtwounblank, cgtwoopen, nullclose, cgtwoioctl, nopoll, cgtwommap
    115  1.35.6.2  nathanw };
    116  1.35.6.2  nathanw 
    117  1.35.6.2  nathanw /*
    118  1.35.6.2  nathanw  * Match a cgtwo.
    119  1.35.6.2  nathanw  */
    120  1.35.6.2  nathanw int
    121  1.35.6.2  nathanw cgtwomatch(parent, cf, aux)
    122  1.35.6.2  nathanw 	struct device *parent;
    123  1.35.6.2  nathanw 	struct cfdata *cf;
    124  1.35.6.2  nathanw 	void *aux;
    125  1.35.6.2  nathanw {
    126  1.35.6.2  nathanw 	struct vme_attach_args	*va = aux;
    127  1.35.6.2  nathanw 	vme_chipset_tag_t	ct = va->va_vct;
    128  1.35.6.2  nathanw 	vme_am_t		mod;
    129  1.35.6.2  nathanw 
    130  1.35.6.2  nathanw 	/*
    131  1.35.6.2  nathanw 	 * Mask out invalid flags from the user.
    132  1.35.6.2  nathanw 	 */
    133  1.35.6.2  nathanw 	cf->cf_flags &= FB_USERMASK;
    134  1.35.6.2  nathanw 
    135  1.35.6.2  nathanw 	mod = 0x3d; /* VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA */
    136  1.35.6.2  nathanw 	if (vme_probe(ct, va->r[0].offset + CG2_CTLREG_OFF, 2, mod, VME_D16,
    137  1.35.6.2  nathanw 			  0, 0)) {
    138  1.35.6.2  nathanw 		return (0);
    139  1.35.6.2  nathanw 	}
    140  1.35.6.2  nathanw 
    141  1.35.6.2  nathanw 	return (1);
    142  1.35.6.2  nathanw }
    143  1.35.6.2  nathanw 
    144  1.35.6.2  nathanw /*
    145  1.35.6.2  nathanw  * Attach a display.  We need to notice if it is the console, too.
    146  1.35.6.2  nathanw  */
    147  1.35.6.2  nathanw void
    148  1.35.6.2  nathanw cgtwoattach(parent, self, aux)
    149  1.35.6.2  nathanw 	struct device *parent, *self;
    150  1.35.6.2  nathanw 	void *aux;
    151  1.35.6.2  nathanw {
    152  1.35.6.2  nathanw 	struct vme_attach_args	*va = aux;
    153  1.35.6.2  nathanw 	vme_chipset_tag_t	ct = va->va_vct;
    154  1.35.6.2  nathanw 	bus_space_tag_t		bt;
    155  1.35.6.2  nathanw 	bus_space_handle_t	bh;
    156  1.35.6.2  nathanw 	vme_am_t		mod;
    157  1.35.6.2  nathanw 	vme_mapresc_t resc;
    158  1.35.6.2  nathanw 	struct cgtwo_softc *sc = (struct cgtwo_softc *)self;
    159  1.35.6.2  nathanw 	struct fbdevice *fb = &sc->sc_fb;
    160  1.35.6.2  nathanw 	struct eeprom *eep = (struct eeprom *)eeprom_va;
    161  1.35.6.2  nathanw 	int isconsole = 0;
    162  1.35.6.2  nathanw 	char *nam = NULL;
    163  1.35.6.2  nathanw 
    164  1.35.6.2  nathanw 	sc->sc_ct = ct;
    165  1.35.6.2  nathanw 	fb->fb_driver = &cgtwofbdriver;
    166  1.35.6.2  nathanw 	fb->fb_device = &sc->sc_dev;
    167  1.35.6.2  nathanw 	fb->fb_type.fb_type = FBTYPE_SUN2COLOR;
    168  1.35.6.2  nathanw 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags;
    169  1.35.6.2  nathanw 
    170  1.35.6.2  nathanw 	fb->fb_type.fb_depth = 8;
    171  1.35.6.2  nathanw 	fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
    172  1.35.6.2  nathanw 
    173  1.35.6.2  nathanw 	fb->fb_type.fb_cmsize = 256;
    174  1.35.6.2  nathanw 	fb->fb_type.fb_size = roundup(CG2_MAPPED_SIZE, NBPG);
    175  1.35.6.2  nathanw 	printf(": %s, %d x %d", nam,
    176  1.35.6.2  nathanw 	       fb->fb_type.fb_width, fb->fb_type.fb_height);
    177  1.35.6.2  nathanw 
    178  1.35.6.2  nathanw 	/*
    179  1.35.6.2  nathanw 	 * When the ROM has mapped in a cgtwo display, the address
    180  1.35.6.2  nathanw 	 * maps only the video RAM, so in any case we have to map the
    181  1.35.6.2  nathanw 	 * registers ourselves.  We only need the video RAM if we are
    182  1.35.6.2  nathanw 	 * going to print characters via rconsole.
    183  1.35.6.2  nathanw 	 */
    184  1.35.6.2  nathanw 	sc->sc_paddr = va->r[0].offset;
    185  1.35.6.2  nathanw 	mod = 0x3d; /* VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA */
    186  1.35.6.2  nathanw 
    187  1.35.6.2  nathanw 	if (vme_space_map(ct, sc->sc_paddr + CG2_ROPMEM_OFF +
    188  1.35.6.2  nathanw 				offsetof(struct cg2fb, status.reg),
    189  1.35.6.2  nathanw 			sizeof(struct cg2statusreg), mod, VME_D16, 0,
    190  1.35.6.2  nathanw 			&bt, &bh, &resc) != 0)
    191  1.35.6.2  nathanw 		panic("cgtwo: vme_map status");
    192  1.35.6.2  nathanw 	sc->sc_bt = bt;
    193  1.35.6.2  nathanw 	sc->sc_reg = (volatile struct cg2statusreg *)bh; /* XXX */
    194  1.35.6.2  nathanw 
    195  1.35.6.2  nathanw 	if (vme_space_map(ct, sc->sc_paddr + CG2_ROPMEM_OFF +
    196  1.35.6.2  nathanw 				offsetof(struct cg2fb, redmap[0]),
    197  1.35.6.2  nathanw 			3 * CG2_CMSIZE, mod, VME_D16, 0,
    198  1.35.6.2  nathanw 			&bt, &bh, &resc) != 0)
    199  1.35.6.2  nathanw 		panic("cgtwo: vme_map cmap");
    200  1.35.6.2  nathanw 	sc->sc_cmap = (volatile u_short *)bh; /* XXX */
    201  1.35.6.2  nathanw 
    202  1.35.6.2  nathanw 	/*
    203  1.35.6.2  nathanw 	 * Assume this is the console if there's no eeprom info
    204  1.35.6.2  nathanw 	 * to be found.
    205  1.35.6.2  nathanw 	 */
    206  1.35.6.2  nathanw 	if (eep == NULL || eep->eeConsole == EE_CONS_COLOR)
    207  1.35.6.2  nathanw 		isconsole = fb_is_console(0);
    208  1.35.6.2  nathanw 	else
    209  1.35.6.2  nathanw 		isconsole = 0;
    210  1.35.6.2  nathanw 
    211  1.35.6.2  nathanw 	if (isconsole) {
    212  1.35.6.2  nathanw 		if (vme_space_map(ct, sc->sc_paddr + CG2_PIXMAP_OFF,
    213  1.35.6.2  nathanw 				CG2_PIXMAP_SIZE, mod, VME_D16, 0,
    214  1.35.6.2  nathanw 				  &bt, &bh, &resc) != 0)
    215  1.35.6.2  nathanw 			panic("cgtwo: vme_map pixels");
    216  1.35.6.2  nathanw 
    217  1.35.6.2  nathanw 		fb->fb_pixels = (caddr_t)bh; /* XXX */
    218  1.35.6.2  nathanw 		printf(" (console)\n");
    219  1.35.6.2  nathanw #ifdef RASTERCONSOLE
    220  1.35.6.2  nathanw 		fbrcons_init(fb);
    221  1.35.6.2  nathanw #endif
    222  1.35.6.2  nathanw 	} else
    223  1.35.6.2  nathanw 		printf("\n");
    224  1.35.6.2  nathanw 
    225  1.35.6.2  nathanw 	fb_attach(fb, isconsole);
    226  1.35.6.2  nathanw }
    227  1.35.6.2  nathanw 
    228  1.35.6.2  nathanw int
    229  1.35.6.2  nathanw cgtwoopen(dev, flags, mode, p)
    230  1.35.6.2  nathanw 	dev_t dev;
    231  1.35.6.2  nathanw 	int flags, mode;
    232  1.35.6.2  nathanw 	struct proc *p;
    233  1.35.6.2  nathanw {
    234  1.35.6.2  nathanw 	int unit = minor(dev);
    235  1.35.6.2  nathanw 
    236  1.35.6.2  nathanw 	if (unit >= cgtwo_cd.cd_ndevs || cgtwo_cd.cd_devs[unit] == NULL)
    237  1.35.6.2  nathanw 		return (ENXIO);
    238  1.35.6.2  nathanw 	return (0);
    239  1.35.6.2  nathanw }
    240  1.35.6.2  nathanw 
    241  1.35.6.2  nathanw int
    242  1.35.6.2  nathanw cgtwoioctl(dev, cmd, data, flags, p)
    243  1.35.6.2  nathanw 	dev_t dev;
    244  1.35.6.2  nathanw 	u_long cmd;
    245  1.35.6.2  nathanw 	register caddr_t data;
    246  1.35.6.2  nathanw 	int flags;
    247  1.35.6.2  nathanw 	struct proc *p;
    248  1.35.6.2  nathanw {
    249  1.35.6.2  nathanw 	register struct cgtwo_softc *sc = cgtwo_cd.cd_devs[minor(dev)];
    250  1.35.6.2  nathanw 	register struct fbgattr *fba;
    251  1.35.6.2  nathanw 
    252  1.35.6.2  nathanw 	switch (cmd) {
    253  1.35.6.2  nathanw 
    254  1.35.6.2  nathanw 	case FBIOGTYPE:
    255  1.35.6.2  nathanw 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    256  1.35.6.2  nathanw 		break;
    257  1.35.6.2  nathanw 
    258  1.35.6.2  nathanw 	case FBIOGATTR:
    259  1.35.6.2  nathanw 		fba = (struct fbgattr *)data;
    260  1.35.6.2  nathanw 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    261  1.35.6.2  nathanw 		fba->owner = 0;		/* XXX ??? */
    262  1.35.6.2  nathanw 		fba->fbtype = sc->sc_fb.fb_type;
    263  1.35.6.2  nathanw 		fba->sattr.flags = 0;
    264  1.35.6.2  nathanw 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    265  1.35.6.2  nathanw 		fba->sattr.dev_specific[0] = -1;
    266  1.35.6.2  nathanw 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    267  1.35.6.2  nathanw 		fba->emu_types[1] = -1;
    268  1.35.6.2  nathanw 		break;
    269  1.35.6.2  nathanw 
    270  1.35.6.2  nathanw 	case FBIOGETCMAP:
    271  1.35.6.2  nathanw 		return cgtwogetcmap(sc, (struct fbcmap *) data);
    272  1.35.6.2  nathanw 
    273  1.35.6.2  nathanw 	case FBIOPUTCMAP:
    274  1.35.6.2  nathanw 		return cgtwoputcmap(sc, (struct fbcmap *) data);
    275  1.35.6.2  nathanw 
    276  1.35.6.2  nathanw 	case FBIOGVIDEO:
    277  1.35.6.2  nathanw 		*(int *)data = sc->sc_reg->video_enab;
    278  1.35.6.2  nathanw 		break;
    279  1.35.6.2  nathanw 
    280  1.35.6.2  nathanw 	case FBIOSVIDEO:
    281  1.35.6.2  nathanw 		sc->sc_reg->video_enab = (*(int*)data) & 1;
    282  1.35.6.2  nathanw 		break;
    283  1.35.6.2  nathanw 
    284  1.35.6.2  nathanw 	default:
    285  1.35.6.2  nathanw 		return (ENOTTY);
    286  1.35.6.2  nathanw 	}
    287  1.35.6.2  nathanw 	return (0);
    288  1.35.6.2  nathanw }
    289  1.35.6.2  nathanw 
    290  1.35.6.2  nathanw /*
    291  1.35.6.2  nathanw  * Undo the effect of an FBIOSVIDEO that turns the video off.
    292  1.35.6.2  nathanw  */
    293  1.35.6.2  nathanw static void
    294  1.35.6.2  nathanw cgtwounblank(dev)
    295  1.35.6.2  nathanw 	struct device *dev;
    296  1.35.6.2  nathanw {
    297  1.35.6.2  nathanw 	struct cgtwo_softc *sc = (struct cgtwo_softc *)dev;
    298  1.35.6.2  nathanw 	sc->sc_reg->video_enab = 1;
    299  1.35.6.2  nathanw }
    300  1.35.6.2  nathanw 
    301  1.35.6.2  nathanw /*
    302  1.35.6.2  nathanw  */
    303  1.35.6.2  nathanw int
    304  1.35.6.2  nathanw cgtwogetcmap(sc, cmap)
    305  1.35.6.2  nathanw 	register struct cgtwo_softc *sc;
    306  1.35.6.2  nathanw 	register struct fbcmap *cmap;
    307  1.35.6.2  nathanw {
    308  1.35.6.2  nathanw 	u_char red[CG2_CMSIZE], green[CG2_CMSIZE], blue[CG2_CMSIZE];
    309  1.35.6.2  nathanw 	int error, start, count, ecount;
    310  1.35.6.2  nathanw 	register u_int i;
    311  1.35.6.2  nathanw 	register volatile u_short *p;
    312  1.35.6.2  nathanw 
    313  1.35.6.2  nathanw 	start = cmap->index;
    314  1.35.6.2  nathanw 	count = cmap->count;
    315  1.35.6.2  nathanw 	ecount = start + count;
    316  1.35.6.2  nathanw 	if (start >= CG2_CMSIZE || count > CG2_CMSIZE - start)
    317  1.35.6.2  nathanw 		return (EINVAL);
    318  1.35.6.2  nathanw 
    319  1.35.6.2  nathanw 	/* XXX - Wait for retrace? */
    320  1.35.6.2  nathanw 
    321  1.35.6.2  nathanw 	/* Copy hardware to local arrays. */
    322  1.35.6.2  nathanw 	p = &sc_redmap(sc)[start];
    323  1.35.6.2  nathanw 	for (i = start; i < ecount; i++)
    324  1.35.6.2  nathanw 		red[i] = *p++;
    325  1.35.6.2  nathanw 	p = &sc_greenmap(sc)[start];
    326  1.35.6.2  nathanw 	for (i = start; i < ecount; i++)
    327  1.35.6.2  nathanw 		green[i] = *p++;
    328  1.35.6.2  nathanw 	p = &sc_bluemap(sc)[start];
    329  1.35.6.2  nathanw 	for (i = start; i < ecount; i++)
    330  1.35.6.2  nathanw 		blue[i] = *p++;
    331  1.35.6.2  nathanw 
    332  1.35.6.2  nathanw 	/* Copy local arrays to user space. */
    333  1.35.6.2  nathanw 	if ((error = copyout(red + start, cmap->red, count)) != 0)
    334  1.35.6.2  nathanw 		return (error);
    335  1.35.6.2  nathanw 	if ((error = copyout(green + start, cmap->green, count)) != 0)
    336  1.35.6.2  nathanw 		return (error);
    337  1.35.6.2  nathanw 	if ((error = copyout(blue + start, cmap->blue, count)) != 0)
    338  1.35.6.2  nathanw 		return (error);
    339  1.35.6.2  nathanw 
    340  1.35.6.2  nathanw 	return (0);
    341  1.35.6.2  nathanw }
    342  1.35.6.2  nathanw 
    343  1.35.6.2  nathanw /*
    344  1.35.6.2  nathanw  */
    345  1.35.6.2  nathanw int
    346  1.35.6.2  nathanw cgtwoputcmap(sc, cmap)
    347  1.35.6.2  nathanw 	register struct cgtwo_softc *sc;
    348  1.35.6.2  nathanw 	register struct fbcmap *cmap;
    349  1.35.6.2  nathanw {
    350  1.35.6.2  nathanw 	u_char red[CG2_CMSIZE], green[CG2_CMSIZE], blue[CG2_CMSIZE];
    351  1.35.6.2  nathanw 	int error;
    352  1.35.6.2  nathanw 	u_int start, count, ecount;
    353  1.35.6.2  nathanw 	register u_int i;
    354  1.35.6.2  nathanw 	register volatile u_short *p;
    355  1.35.6.2  nathanw 
    356  1.35.6.2  nathanw 	start = cmap->index;
    357  1.35.6.2  nathanw 	count = cmap->count;
    358  1.35.6.2  nathanw 	ecount = start + count;
    359  1.35.6.2  nathanw 	if (start >= CG2_CMSIZE || count > CG2_CMSIZE - start)
    360  1.35.6.2  nathanw 		return (EINVAL);
    361  1.35.6.2  nathanw 
    362  1.35.6.2  nathanw 	/* Copy from user space to local arrays. */
    363  1.35.6.2  nathanw 	if ((error = copyin(cmap->red, red + start, count)) != 0)
    364  1.35.6.2  nathanw 		return (error);
    365  1.35.6.2  nathanw 	if ((error = copyin(cmap->green, green + start, count)) != 0)
    366  1.35.6.2  nathanw 		return (error);
    367  1.35.6.2  nathanw 	if ((error = copyin(cmap->blue, blue + start, count)) != 0)
    368  1.35.6.2  nathanw 		return (error);
    369  1.35.6.2  nathanw 
    370  1.35.6.2  nathanw 	/* XXX - Wait for retrace? */
    371  1.35.6.2  nathanw 
    372  1.35.6.2  nathanw 	/* Copy from local arrays to hardware. */
    373  1.35.6.2  nathanw 	p = &sc_redmap(sc)[start];
    374  1.35.6.2  nathanw 	for (i = start; i < ecount; i++)
    375  1.35.6.2  nathanw 		*p++ = red[i];
    376  1.35.6.2  nathanw 	p = &sc_greenmap(sc)[start];
    377  1.35.6.2  nathanw 	for (i = start; i < ecount; i++)
    378  1.35.6.2  nathanw 		*p++ = green[i];
    379  1.35.6.2  nathanw 	p = &sc_bluemap(sc)[start];
    380  1.35.6.2  nathanw 	for (i = start; i < ecount; i++)
    381  1.35.6.2  nathanw 		*p++ = blue[i];
    382  1.35.6.2  nathanw 
    383  1.35.6.2  nathanw 	return (0);
    384  1.35.6.2  nathanw }
    385  1.35.6.2  nathanw 
    386  1.35.6.2  nathanw /*
    387  1.35.6.2  nathanw  * Return the address that would map the given device at the given
    388  1.35.6.2  nathanw  * offset, allowing for the given protection, or return -1 for error.
    389  1.35.6.2  nathanw  */
    390  1.35.6.2  nathanw paddr_t
    391  1.35.6.2  nathanw cgtwommap(dev, off, prot)
    392  1.35.6.2  nathanw 	dev_t dev;
    393  1.35.6.2  nathanw 	off_t off;
    394  1.35.6.2  nathanw 	int prot;
    395  1.35.6.2  nathanw {
    396  1.35.6.2  nathanw 	register struct cgtwo_softc *sc = cgtwo_cd.cd_devs[minor(dev)];
    397  1.35.6.2  nathanw 	vme_am_t mod;
    398  1.35.6.2  nathanw 	bus_space_handle_t bh;
    399  1.35.6.2  nathanw 	extern int sparc_vme_mmap_cookie __P((vme_addr_t, vme_am_t,
    400  1.35.6.2  nathanw 					      bus_space_handle_t *));
    401  1.35.6.2  nathanw 
    402  1.35.6.2  nathanw 	if (off & PGOFSET)
    403  1.35.6.2  nathanw 		panic("cgtwommap");
    404  1.35.6.2  nathanw 
    405  1.35.6.2  nathanw 	if (off >= sc->sc_fb.fb_type.fb_size)
    406  1.35.6.2  nathanw 		return (-1);
    407  1.35.6.2  nathanw 
    408  1.35.6.2  nathanw 	/* Apparently, the pixels are in 32-bit data space */
    409  1.35.6.2  nathanw 	mod = 0x3d; /* VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA */
    410  1.35.6.2  nathanw 
    411  1.35.6.2  nathanw 	if (sparc_vme_mmap_cookie(sc->sc_paddr + off, mod, &bh) != 0)
    412  1.35.6.2  nathanw 		panic("cgtwommap");
    413  1.35.6.2  nathanw 
    414  1.35.6.2  nathanw 	return ((paddr_t)bh);
    415  1.35.6.2  nathanw }
    416