Home | History | Annotate | Line # | Download | only in dev
grf.c revision 1.11
      1   1.1      mw /*
      2   1.1      mw  * Copyright (c) 1988 University of Utah.
      3   1.1      mw  * Copyright (c) 1990 The Regents of the University of California.
      4   1.1      mw  * All rights reserved.
      5   1.1      mw  *
      6   1.1      mw  * This code is derived from software contributed to Berkeley by
      7   1.1      mw  * the Systems Programming Group of the University of Utah Computer
      8   1.1      mw  * Science Department.
      9   1.1      mw  *
     10   1.1      mw  * Redistribution and use in source and binary forms, with or without
     11   1.1      mw  * modification, are permitted provided that the following conditions
     12   1.1      mw  * are met:
     13   1.1      mw  * 1. Redistributions of source code must retain the above copyright
     14   1.1      mw  *    notice, this list of conditions and the following disclaimer.
     15   1.1      mw  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1      mw  *    notice, this list of conditions and the following disclaimer in the
     17   1.1      mw  *    documentation and/or other materials provided with the distribution.
     18   1.1      mw  * 3. All advertising materials mentioning features or use of this software
     19   1.1      mw  *    must display the following acknowledgement:
     20   1.1      mw  *	This product includes software developed by the University of
     21   1.1      mw  *	California, Berkeley and its contributors.
     22   1.1      mw  * 4. Neither the name of the University nor the names of its contributors
     23   1.1      mw  *    may be used to endorse or promote products derived from this software
     24   1.1      mw  *    without specific prior written permission.
     25   1.1      mw  *
     26   1.1      mw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27   1.1      mw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28   1.1      mw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29   1.1      mw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30   1.1      mw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31   1.1      mw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32   1.1      mw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33   1.1      mw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34   1.1      mw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35   1.1      mw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36   1.1      mw  * SUCH DAMAGE.
     37   1.1      mw  *
     38   1.4      mw  * from: Utah $Hdr: grf.c 1.31 91/01/21$
     39   1.4      mw  *
     40   1.4      mw  *	@(#)grf.c	7.8 (Berkeley) 5/7/91
     41  1.11  chopps  *	$Id: grf.c,v 1.11 1994/05/08 05:53:03 chopps Exp $
     42   1.1      mw  */
     43   1.1      mw 
     44   1.1      mw /*
     45  1.11  chopps  * Graphics display driver for the Amiga
     46   1.1      mw  * This is the hardware-independent portion of the driver.
     47  1.11  chopps  * Hardware access is through the grf_softc->g_mode routine.
     48   1.1      mw  */
     49   1.1      mw 
     50   1.8  chopps #include <sys/param.h>
     51   1.8  chopps #include <sys/proc.h>
     52   1.8  chopps #include <sys/ioctl.h>
     53  1.11  chopps #include <sys/device.h>
     54   1.8  chopps #include <sys/file.h>
     55   1.8  chopps #include <sys/malloc.h>
     56   1.9  chopps #include <sys/conf.h>
     57   1.9  chopps #include <sys/systm.h>
     58  1.11  chopps #include <sys/vnode.h>
     59  1.11  chopps #include <sys/mman.h>
     60   1.8  chopps #include <vm/vm.h>
     61   1.8  chopps #include <vm/vm_kern.h>
     62   1.8  chopps #include <vm/vm_page.h>
     63   1.8  chopps #include <vm/vm_pager.h>
     64  1.11  chopps #include <machine/cpu.h>
     65  1.11  chopps #include <amiga/amiga/color.h>	/* DEBUG */
     66  1.11  chopps #include <amiga/amiga/device.h>
     67  1.11  chopps #include <amiga/dev/grfioctl.h>
     68  1.11  chopps #include <amiga/dev/grfvar.h>
     69  1.11  chopps #include <amiga/dev/itevar.h>
     70   1.8  chopps 
     71  1.11  chopps #include "grf.h"
     72  1.11  chopps #if NGRF > 0
     73   1.9  chopps 
     74   1.1      mw #include "ite.h"
     75   1.1      mw #if NITE == 0
     76   1.9  chopps #define	ite_on(u,f)
     77   1.9  chopps #define	ite_off(u,f)
     78   1.9  chopps #define ite_reinit(d)
     79   1.1      mw #endif
     80   1.1      mw 
     81  1.11  chopps int grfopen __P((dev_t, int, int, struct proc *));
     82  1.11  chopps int grfclose __P((dev_t, int));
     83  1.11  chopps int grfioctl __P((dev_t, int, caddr_t, int, struct proc *));
     84  1.11  chopps int grfselect __P((dev_t, int));
     85  1.11  chopps int grfmap __P((dev_t, int, int));
     86  1.11  chopps 
     87  1.11  chopps int grfon __P((dev_t));
     88  1.11  chopps int grfoff __P((dev_t));
     89  1.11  chopps int grfsinfo __P((dev_t, struct grfdyninfo *));
     90  1.11  chopps #ifdef BANKEDDEVPAGER
     91  1.11  chopps int grfbanked_get __P((dev_t, off_t, int));
     92  1.11  chopps int grfbanked_cur __P((dev_t));
     93  1.11  chopps int grfbanked_set __P((dev_t, int));
     94   1.1      mw #endif
     95   1.1      mw 
     96  1.11  chopps void grfattach __P((struct device *, struct device *, void *));
     97  1.11  chopps int grfmatch __P((struct device *, struct cfdata *, void *));
     98  1.11  chopps int grfprint __P((void *, char *));
     99   1.1      mw /*
    100  1.11  chopps  * pointers to grf drivers device structs
    101   1.1      mw  */
    102  1.11  chopps struct grf_softc *grfsp[NGRF];
    103  1.11  chopps 
    104  1.11  chopps 
    105  1.11  chopps struct cfdriver grfcd = {
    106  1.11  chopps 	NULL, "grf", grfmatch, grfattach, DV_DULL,
    107  1.11  chopps 	sizeof(struct device), NULL, 0 };
    108  1.11  chopps 
    109  1.11  chopps /*
    110  1.11  chopps  * only used in console init.
    111  1.11  chopps  */
    112  1.11  chopps static struct cfdata *cfdata;
    113  1.11  chopps 
    114  1.11  chopps /*
    115  1.11  chopps  * match if the unit of grf matches its perspective
    116  1.11  chopps  * low level board driver.
    117  1.11  chopps  */
    118  1.11  chopps int
    119  1.11  chopps grfmatch(pdp, cfp, auxp)
    120  1.11  chopps 	struct device *pdp;
    121  1.11  chopps 	struct cfdata *cfp;
    122  1.11  chopps 	void *auxp;
    123   1.1      mw {
    124  1.11  chopps 	if (cfp->cf_unit != ((struct grf_softc *)pdp)->g_unit)
    125  1.11  chopps 		return(0);
    126  1.11  chopps 	cfdata = cfp;
    127  1.11  chopps 	return(1);
    128   1.1      mw }
    129   1.1      mw 
    130   1.1      mw /*
    131  1.11  chopps  * attach.. plug pointer in and print some info.
    132  1.11  chopps  * then try and attach an ite to us. note: dp is NULL
    133  1.11  chopps  * durring console init.
    134   1.1      mw  */
    135  1.11  chopps void
    136  1.11  chopps grfattach(pdp, dp, auxp)
    137  1.11  chopps 	struct device *pdp, *dp;
    138  1.11  chopps 	void *auxp;
    139   1.1      mw {
    140  1.11  chopps 	struct grf_softc *gp;
    141  1.11  chopps 	int maj;
    142  1.11  chopps 
    143  1.11  chopps 	gp = (struct grf_softc *)pdp;
    144  1.11  chopps 	grfsp[gp->g_unit] = (struct grf_softc *)pdp;
    145   1.1      mw 
    146  1.11  chopps 	/*
    147  1.11  chopps 	 * find our major device number
    148  1.11  chopps 	 */
    149  1.11  chopps 	for(maj = 0; maj < nchrdev; maj++)
    150  1.11  chopps 		if (cdevsw[maj].d_open == grfopen)
    151  1.11  chopps 			break;
    152  1.11  chopps 
    153  1.11  chopps 	gp->g_grfdev = makedev(maj, gp->g_unit);
    154  1.11  chopps 	if (dp != NULL) {
    155  1.11  chopps 		printf(" %d x %d", gp->g_display.gd_dwidth,
    156  1.11  chopps 		    gp->g_display.gd_dheight);
    157  1.11  chopps 		if (gp->g_display.gd_colors == 2)
    158  1.11  chopps 			printf(", monochrome\n");
    159  1.11  chopps 		else
    160  1.11  chopps 			printf(", %d colors\n", gp->g_display.gd_colors);
    161  1.11  chopps 	}
    162  1.11  chopps 
    163  1.11  chopps 	/*
    164  1.11  chopps 	 * try and attach an ite
    165  1.11  chopps 	 */
    166  1.11  chopps 	amiga_config_found(cfdata, dp, gp, grfprint);
    167   1.1      mw }
    168   1.1      mw 
    169  1.11  chopps int
    170  1.11  chopps grfprint(auxp, pnp)
    171  1.11  chopps 	void *auxp;
    172  1.11  chopps 	char *pnp;
    173  1.11  chopps {
    174  1.11  chopps 	if (pnp)
    175  1.11  chopps 		printf("ite%d at %s", ((struct grf_softc *)auxp)->g_unit,
    176  1.11  chopps 		    pnp);
    177  1.11  chopps 	return(UNCONF);
    178   1.1      mw }
    179   1.1      mw 
    180   1.1      mw /*ARGSUSED*/
    181  1.11  chopps int
    182  1.11  chopps grfopen(dev, flags, devtype, p)
    183   1.1      mw 	dev_t dev;
    184  1.11  chopps 	int flags, devtype;
    185  1.11  chopps 	struct proc *p;
    186   1.1      mw {
    187  1.11  chopps 	struct grf_softc *gp;
    188  1.11  chopps 
    189  1.11  chopps 	if (GRFUNIT(dev) >= NGRF)
    190  1.11  chopps 		return(ENXIO);
    191   1.1      mw 
    192  1.11  chopps 	gp = grfsp[GRFUNIT(dev)];
    193  1.11  chopps 
    194  1.11  chopps 	if ((gp->g_flags & GF_ALIVE) == 0)
    195   1.1      mw 		return(ENXIO);
    196  1.11  chopps 
    197   1.1      mw 	if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
    198   1.1      mw 		return(EBUSY);
    199  1.11  chopps 
    200  1.11  chopps 	return(0);
    201   1.1      mw }
    202   1.1      mw 
    203   1.1      mw /*ARGSUSED*/
    204  1.11  chopps int
    205   1.1      mw grfclose(dev, flags)
    206   1.1      mw 	dev_t dev;
    207  1.11  chopps 	int flags;
    208   1.1      mw {
    209  1.11  chopps 	struct grf_softc *gp;
    210   1.1      mw 
    211  1.11  chopps 	gp = grfsp[GRFUNIT(dev)];
    212  1.11  chopps 	(void)grfoff(dev);
    213   1.1      mw 	gp->g_flags &= GF_ALIVE;
    214   1.1      mw 	return(0);
    215   1.1      mw }
    216   1.1      mw 
    217   1.1      mw /*ARGSUSED*/
    218  1.11  chopps int
    219   1.1      mw grfioctl(dev, cmd, data, flag, p)
    220   1.1      mw 	dev_t dev;
    221  1.11  chopps 	int cmd, flag;
    222   1.1      mw 	caddr_t data;
    223   1.1      mw 	struct proc *p;
    224   1.1      mw {
    225  1.11  chopps 	struct grf_softc *gp;
    226   1.1      mw 	int error;
    227   1.1      mw 
    228  1.11  chopps 	gp = grfsp[GRFUNIT(dev)];
    229   1.1      mw 	error = 0;
    230  1.11  chopps 
    231   1.1      mw 	switch (cmd) {
    232   1.5      mw 	case OGRFIOCGINFO:
    233   1.5      mw 	        /* argl.. no bank-member.. */
    234   1.5      mw 	  	bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo)-4);
    235   1.5      mw 		break;
    236   1.1      mw 	case GRFIOCGINFO:
    237   1.1      mw 		bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo));
    238   1.1      mw 		break;
    239   1.1      mw 	case GRFIOCON:
    240   1.1      mw 		error = grfon(dev);
    241   1.1      mw 		break;
    242   1.1      mw 	case GRFIOCOFF:
    243   1.1      mw 		error = grfoff(dev);
    244   1.1      mw 		break;
    245   1.1      mw 	case GRFIOCSINFO:
    246  1.11  chopps 		error = grfsinfo(dev, (struct grfdyninfo *) data);
    247   1.1      mw 		break;
    248   1.3      mw 	case GRFGETVMODE:
    249  1.11  chopps 		return(gp->g_mode(gp, GM_GRFGETVMODE, data));
    250   1.3      mw 	case GRFSETVMODE:
    251  1.11  chopps 		error = gp->g_mode(gp, GM_GRFSETVMODE, data);
    252  1.11  chopps 		if (error == 0 && gp->g_itedev)
    253  1.11  chopps 			ite_reinit(gp->g_itedev);
    254   1.3      mw 		break;
    255   1.3      mw 	case GRFGETNUMVM:
    256  1.11  chopps 		return(gp->g_mode(gp, GM_GRFGETNUMVM, data));
    257  1.11  chopps 	/*
    258  1.11  chopps 	 * these are all hardware dependant, and have to be resolved
    259  1.11  chopps 	 * in the respective driver.
    260  1.11  chopps 	 */
    261   1.5      mw 	case GRFIOCPUTCMAP:
    262   1.5      mw 	case GRFIOCGETCMAP:
    263   1.5      mw 	case GRFIOCSSPRITEPOS:
    264   1.5      mw 	case GRFIOCGSPRITEPOS:
    265   1.5      mw 	case GRFIOCSSPRITEINF:
    266   1.5      mw 	case GRFIOCGSPRITEINF:
    267   1.5      mw 	case GRFIOCGSPRITEMAX:
    268  1.11  chopps 		return(gp->g_mode(gp, GM_GRFIOCTL, cmd, data));
    269   1.1      mw 	default:
    270  1.11  chopps 		/*
    271  1.11  chopps 		 * check to see whether it's a command recognized by the
    272  1.11  chopps 		 * view code if the unit is 0
    273  1.11  chopps 		 * XXX
    274  1.11  chopps 		 */
    275   1.5      mw 		if (GRFUNIT(dev) == 0)
    276  1.11  chopps 			return(viewioctl(dev, cmd, data, flag, p));
    277   1.1      mw 		error = EINVAL;
    278   1.1      mw 		break;
    279   1.1      mw 
    280   1.1      mw 	}
    281   1.1      mw 	return(error);
    282   1.1      mw }
    283   1.1      mw 
    284   1.1      mw /*ARGSUSED*/
    285  1.11  chopps int
    286   1.1      mw grfselect(dev, rw)
    287   1.1      mw 	dev_t dev;
    288  1.11  chopps 	int rw;
    289   1.1      mw {
    290   1.1      mw 	if (rw == FREAD)
    291   1.1      mw 		return(0);
    292   1.1      mw 	return(1);
    293   1.1      mw }
    294   1.1      mw 
    295  1.11  chopps /*
    296  1.11  chopps  * map the contents of a graphics display card into process'
    297  1.11  chopps  * memory space.
    298  1.11  chopps  */
    299  1.11  chopps int
    300  1.11  chopps grfmap(dev, off, prot)
    301  1.11  chopps 	dev_t dev;
    302  1.11  chopps 	int off, prot;
    303   1.1      mw {
    304  1.11  chopps 	struct grf_softc *gp;
    305  1.11  chopps 	struct grfinfo *gi;
    306  1.11  chopps 
    307  1.11  chopps 	gp = grfsp[GRFUNIT(dev)];
    308  1.11  chopps 	gi = &gp->g_display;
    309   1.1      mw 
    310  1.11  chopps 	/*
    311  1.11  chopps 	 * control registers
    312  1.11  chopps 	 */
    313  1.11  chopps 	if (off >= 0 && off < gi->gd_regsize)
    314  1.11  chopps 		return(((u_int)gi->gd_regaddr + off) >> PGSHIFT);
    315   1.1      mw 
    316  1.11  chopps 	/*
    317  1.11  chopps 	 * frame buffer
    318  1.11  chopps 	 */
    319  1.11  chopps 	if (off >= gi->gd_regsize && off < gi->gd_regsize+gi->gd_fbsize) {
    320  1.11  chopps 		off -= gi->gd_regsize;
    321  1.11  chopps #ifdef BANKEDDEVPAGER
    322  1.11  chopps 		if (gi->gd_bank_size)
    323  1.11  chopps 			off %= gi->gd_bank_size;
    324   1.1      mw #endif
    325  1.11  chopps 		return(((u_int)gi->gd_fbaddr + off) >> PGSHIFT);
    326   1.1      mw 	}
    327  1.11  chopps 	/* bogus */
    328  1.11  chopps 	return(-1);
    329   1.1      mw }
    330   1.1      mw 
    331  1.11  chopps int
    332  1.11  chopps grfon(dev)
    333   1.1      mw 	dev_t dev;
    334   1.1      mw {
    335  1.11  chopps 	struct grf_softc *gp;
    336   1.1      mw 
    337  1.11  chopps 	gp = grfsp[GRFUNIT(dev)];
    338   1.1      mw 
    339   1.3      mw 	if (gp->g_flags & GF_GRFON)
    340  1.11  chopps 		return(0);
    341  1.11  chopps 
    342   1.3      mw 	gp->g_flags |= GF_GRFON;
    343  1.11  chopps 	if (gp->g_itedev != NODEV)
    344  1.11  chopps 		ite_off(gp->g_itedev, 3);
    345   1.3      mw 
    346  1.11  chopps 	return(gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVON : GM_GRFON));
    347   1.1      mw }
    348   1.1      mw 
    349  1.11  chopps int
    350   1.1      mw grfoff(dev)
    351   1.1      mw 	dev_t dev;
    352   1.1      mw {
    353  1.11  chopps 	struct grf_softc *gp;
    354   1.1      mw 	int error;
    355   1.3      mw 
    356  1.11  chopps 	gp = grfsp[GRFUNIT(dev)];
    357  1.11  chopps 
    358  1.11  chopps 	if ((gp->g_flags & GF_GRFON) == 0)
    359  1.11  chopps 		return(0);
    360  1.11  chopps 
    361   1.3      mw 	gp->g_flags &= ~GF_GRFON;
    362  1.11  chopps 	error = gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF);
    363  1.11  chopps 
    364  1.11  chopps 	/*
    365  1.11  chopps 	 * Closely tied together no X's
    366  1.11  chopps 	 */
    367  1.11  chopps 	if (gp->g_itedev != NODEV)
    368  1.11  chopps 		ite_on(gp->g_itedev, 2);
    369   1.1      mw 
    370   1.1      mw 	return(error);
    371   1.1      mw }
    372   1.1      mw 
    373  1.11  chopps int
    374   1.1      mw grfsinfo(dev, dyninfo)
    375   1.1      mw 	dev_t dev;
    376   1.1      mw 	struct grfdyninfo *dyninfo;
    377   1.1      mw {
    378  1.11  chopps 	struct grf_softc *gp;
    379   1.1      mw 	int error;
    380   1.1      mw 
    381  1.11  chopps 	gp = grfsp[GRFUNIT(dev)];
    382  1.11  chopps 	error = gp->g_mode(gp, GM_GRFCONFIG, dyninfo);
    383   1.1      mw 
    384  1.11  chopps 	/*
    385  1.11  chopps 	 * Closely tied together no X's
    386  1.11  chopps 	 */
    387  1.11  chopps 	if (gp->g_itedev != NODEV)
    388  1.11  chopps 		ite_reinit(gp->g_itedev);
    389   1.1      mw 	return(error);
    390   1.1      mw }
    391   1.1      mw 
    392   1.5      mw #ifdef BANKEDDEVPAGER
    393   1.5      mw 
    394   1.5      mw int
    395   1.5      mw grfbanked_get (dev, off, prot)
    396   1.5      mw      dev_t dev;
    397   1.5      mw      off_t off;
    398   1.5      mw      int   prot;
    399   1.5      mw {
    400  1.11  chopps 	struct grf_softc *gp;
    401  1.11  chopps 	struct grfinfo *gi;
    402  1.11  chopps 	int error, bank;
    403  1.11  chopps 
    404  1.11  chopps 	gp = grfsp[GRFUNIT(dev)];
    405  1.11  chopps 	gi = &gp->g_display;
    406  1.11  chopps 
    407  1.11  chopps 	off -= gi->gd_regsize;
    408  1.11  chopps 	if (off < 0 || off >= gi->gd_fbsize)
    409  1.11  chopps 		return -1;
    410   1.5      mw 
    411  1.11  chopps 	error = gp->g_mode(gp, GM_GRFGETBANK, &bank, off, prot);
    412  1.11  chopps 	return error ? -1 : bank;
    413   1.5      mw }
    414   1.5      mw 
    415   1.5      mw int
    416   1.5      mw grfbanked_cur (dev)
    417  1.11  chopps 	dev_t dev;
    418   1.5      mw {
    419  1.11  chopps 	struct grf_softc *gp;
    420  1.11  chopps 	int error, bank;
    421   1.5      mw 
    422  1.11  chopps 	gp = grfsp[GRFUNIT(dev)];
    423  1.11  chopps 
    424  1.11  chopps 	error = gp->g_mode(gp, GM_GRFGETCURBANK, &bank);
    425  1.11  chopps 	return(error ? -1 : bank);
    426   1.5      mw }
    427   1.5      mw 
    428   1.5      mw int
    429   1.5      mw grfbanked_set (dev, bank)
    430  1.11  chopps 	dev_t dev;
    431  1.11  chopps 	int bank;
    432   1.5      mw {
    433  1.11  chopps 	struct grf_softc *gp;
    434   1.5      mw 
    435  1.11  chopps 	gp = grfsp[GRFUNIT(dev)];
    436  1.11  chopps 	return(gp->g_mode(gp, GM_GRFSETBANK, bank) ? -1 : 0);
    437   1.5      mw }
    438   1.5      mw 
    439   1.5      mw #endif /* BANKEDDEVPAGER */
    440   1.1      mw #endif	/* NGRF > 0 */
    441