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