Home | History | Annotate | Line # | Download | only in dev
grf.c revision 1.43
      1  1.43   thorpej /*	$NetBSD: grf.c,v 1.43 2002/09/27 20:29:56 thorpej Exp $ */
      2  1.15       cgd 
      3   1.1        mw /*
      4   1.1        mw  * Copyright (c) 1988 University of Utah.
      5   1.1        mw  * Copyright (c) 1990 The Regents of the University of California.
      6   1.1        mw  * All rights reserved.
      7   1.1        mw  *
      8   1.1        mw  * This code is derived from software contributed to Berkeley by
      9   1.1        mw  * the Systems Programming Group of the University of Utah Computer
     10   1.1        mw  * Science Department.
     11   1.1        mw  *
     12   1.1        mw  * Redistribution and use in source and binary forms, with or without
     13   1.1        mw  * modification, are permitted provided that the following conditions
     14   1.1        mw  * are met:
     15   1.1        mw  * 1. Redistributions of source code must retain the above copyright
     16   1.1        mw  *    notice, this list of conditions and the following disclaimer.
     17   1.1        mw  * 2. Redistributions in binary form must reproduce the above copyright
     18   1.1        mw  *    notice, this list of conditions and the following disclaimer in the
     19   1.1        mw  *    documentation and/or other materials provided with the distribution.
     20   1.1        mw  * 3. All advertising materials mentioning features or use of this software
     21   1.1        mw  *    must display the following acknowledgement:
     22   1.1        mw  *	This product includes software developed by the University of
     23   1.1        mw  *	California, Berkeley and its contributors.
     24   1.1        mw  * 4. Neither the name of the University nor the names of its contributors
     25   1.1        mw  *    may be used to endorse or promote products derived from this software
     26   1.1        mw  *    without specific prior written permission.
     27   1.1        mw  *
     28   1.1        mw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29   1.1        mw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30   1.1        mw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31   1.1        mw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32   1.1        mw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33   1.1        mw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34   1.1        mw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35   1.1        mw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36   1.1        mw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37   1.1        mw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38   1.1        mw  * SUCH DAMAGE.
     39   1.1        mw  *
     40   1.4        mw  * from: Utah $Hdr: grf.c 1.31 91/01/21$
     41   1.4        mw  *
     42   1.4        mw  *	@(#)grf.c	7.8 (Berkeley) 5/7/91
     43   1.1        mw  */
     44  1.40   aymeric 
     45  1.40   aymeric #include <sys/cdefs.h>
     46  1.43   thorpej __KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.43 2002/09/27 20:29:56 thorpej Exp $");
     47   1.1        mw 
     48   1.1        mw /*
     49  1.11    chopps  * Graphics display driver for the Amiga
     50   1.1        mw  * This is the hardware-independent portion of the driver.
     51  1.11    chopps  * Hardware access is through the grf_softc->g_mode routine.
     52   1.1        mw  */
     53   1.1        mw 
     54   1.8    chopps #include <sys/param.h>
     55   1.8    chopps #include <sys/proc.h>
     56   1.8    chopps #include <sys/ioctl.h>
     57  1.11    chopps #include <sys/device.h>
     58   1.8    chopps #include <sys/file.h>
     59   1.8    chopps #include <sys/malloc.h>
     60   1.9    chopps #include <sys/systm.h>
     61  1.11    chopps #include <sys/vnode.h>
     62  1.11    chopps #include <sys/mman.h>
     63  1.30    mhitch #include <sys/poll.h>
     64  1.36       mrg #include <uvm/uvm_extern.h>
     65  1.11    chopps #include <machine/cpu.h>
     66  1.38   thorpej #include <dev/sun/fbio.h>
     67  1.11    chopps #include <amiga/amiga/color.h>	/* DEBUG */
     68  1.11    chopps #include <amiga/amiga/device.h>
     69  1.11    chopps #include <amiga/dev/grfioctl.h>
     70  1.11    chopps #include <amiga/dev/grfvar.h>
     71  1.11    chopps #include <amiga/dev/itevar.h>
     72  1.26     veego #include <amiga/dev/viewioctl.h>
     73  1.26     veego 
     74  1.26     veego #include <sys/conf.h>
     75   1.8    chopps 
     76  1.21    chopps #include "view.h"
     77  1.26     veego #include "grf.h"
     78  1.21    chopps 
     79  1.11    chopps #if NGRF > 0
     80   1.1        mw #include "ite.h"
     81   1.1        mw #if NITE == 0
     82   1.9    chopps #define	ite_on(u,f)
     83   1.9    chopps #define	ite_off(u,f)
     84   1.9    chopps #define ite_reinit(d)
     85   1.1        mw #endif
     86   1.1        mw 
     87  1.39   aymeric int grfon(dev_t);
     88  1.39   aymeric int grfoff(dev_t);
     89  1.39   aymeric int grfsinfo(dev_t, struct grfdyninfo *);
     90   1.1        mw 
     91  1.39   aymeric void grfattach(struct device *, struct device *, void *);
     92  1.39   aymeric int grfmatch(struct device *, struct cfdata *, void *);
     93  1.39   aymeric int grfprint(void *, const char *);
     94   1.1        mw /*
     95  1.39   aymeric  * pointers to grf drivers device structs
     96   1.1        mw  */
     97  1.11    chopps struct grf_softc *grfsp[NGRF];
     98  1.11    chopps 
     99  1.43   thorpej const struct cfattach grf_ca = {
    100  1.25   thorpej 	sizeof(struct device), grfmatch, grfattach
    101  1.25   thorpej };
    102  1.11    chopps 
    103  1.42   gehenna dev_type_open(grfopen);
    104  1.42   gehenna dev_type_close(grfclose);
    105  1.42   gehenna dev_type_ioctl(grfioctl);
    106  1.42   gehenna dev_type_poll(grfpoll);
    107  1.42   gehenna dev_type_mmap(grfmmap);
    108  1.42   gehenna 
    109  1.42   gehenna const struct cdevsw grf_cdevsw = {
    110  1.42   gehenna 	grfopen, grfclose, nullread, nullwrite, grfioctl,
    111  1.42   gehenna 	nostop, notty, grfpoll, grfmmap,
    112  1.42   gehenna };
    113  1.42   gehenna 
    114  1.11    chopps /*
    115  1.11    chopps  * only used in console init.
    116  1.11    chopps  */
    117  1.11    chopps static struct cfdata *cfdata;
    118  1.11    chopps 
    119  1.11    chopps /*
    120  1.39   aymeric  * match if the unit of grf matches its perspective
    121  1.11    chopps  * low level board driver.
    122  1.11    chopps  */
    123  1.11    chopps int
    124  1.39   aymeric grfmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
    125   1.1        mw {
    126  1.25   thorpej 
    127  1.11    chopps 	if (cfp->cf_unit != ((struct grf_softc *)pdp)->g_unit)
    128  1.11    chopps 		return(0);
    129  1.11    chopps 	cfdata = cfp;
    130  1.11    chopps 	return(1);
    131   1.1        mw }
    132   1.1        mw 
    133   1.1        mw /*
    134  1.11    chopps  * attach.. plug pointer in and print some info.
    135  1.11    chopps  * then try and attach an ite to us. note: dp is NULL
    136  1.11    chopps  * durring console init.
    137   1.1        mw  */
    138  1.11    chopps void
    139  1.39   aymeric grfattach(struct device *pdp, struct device *dp, void *auxp)
    140   1.1        mw {
    141  1.11    chopps 	struct grf_softc *gp;
    142  1.11    chopps 	int maj;
    143  1.11    chopps 
    144  1.11    chopps 	gp = (struct grf_softc *)pdp;
    145  1.11    chopps 	grfsp[gp->g_unit] = (struct grf_softc *)pdp;
    146   1.1        mw 
    147  1.11    chopps 	/*
    148  1.39   aymeric 	 * find our major device number
    149  1.11    chopps 	 */
    150  1.42   gehenna 	maj = cdevsw_lookup_major(&grf_cdevsw);
    151  1.11    chopps 
    152  1.11    chopps 	gp->g_grfdev = makedev(maj, gp->g_unit);
    153  1.11    chopps 	if (dp != NULL) {
    154  1.31  christos 		printf(": width %d height %d", gp->g_display.gd_dwidth,
    155  1.11    chopps 		    gp->g_display.gd_dheight);
    156  1.11    chopps 		if (gp->g_display.gd_colors == 2)
    157  1.31  christos 			printf(" monochrome\n");
    158  1.11    chopps 		else
    159  1.31  christos 			printf(" colors %d\n", gp->g_display.gd_colors);
    160  1.11    chopps 	}
    161  1.39   aymeric 
    162  1.11    chopps 	/*
    163  1.11    chopps 	 * try and attach an ite
    164  1.11    chopps 	 */
    165  1.11    chopps 	amiga_config_found(cfdata, dp, gp, grfprint);
    166   1.1        mw }
    167   1.1        mw 
    168  1.11    chopps int
    169  1.39   aymeric grfprint(void *auxp, const char *pnp)
    170  1.11    chopps {
    171  1.11    chopps 	if (pnp)
    172  1.31  christos 		printf("ite at %s", pnp);
    173  1.11    chopps 	return(UNCONF);
    174   1.1        mw }
    175   1.1        mw 
    176   1.1        mw /*ARGSUSED*/
    177  1.11    chopps int
    178  1.39   aymeric grfopen(dev_t dev, int flags, int devtype, struct proc *p)
    179   1.1        mw {
    180  1.11    chopps 	struct grf_softc *gp;
    181  1.11    chopps 
    182  1.24       jtc 	if (GRFUNIT(dev) >= NGRF || (gp = grfsp[GRFUNIT(dev)]) == NULL)
    183  1.11    chopps 		return(ENXIO);
    184  1.11    chopps 
    185  1.11    chopps 	if ((gp->g_flags & GF_ALIVE) == 0)
    186   1.1        mw 		return(ENXIO);
    187  1.11    chopps 
    188   1.1        mw 	if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
    189   1.1        mw 		return(EBUSY);
    190  1.11    chopps 
    191  1.11    chopps 	return(0);
    192   1.1        mw }
    193   1.1        mw 
    194   1.1        mw /*ARGSUSED*/
    195  1.11    chopps int
    196  1.39   aymeric grfclose(dev_t dev, int flags, int mode, struct proc *p)
    197   1.1        mw {
    198  1.11    chopps 	struct grf_softc *gp;
    199   1.1        mw 
    200  1.11    chopps 	gp = grfsp[GRFUNIT(dev)];
    201  1.11    chopps 	(void)grfoff(dev);
    202   1.1        mw 	gp->g_flags &= GF_ALIVE;
    203   1.1        mw 	return(0);
    204   1.1        mw }
    205   1.1        mw 
    206   1.1        mw /*ARGSUSED*/
    207  1.11    chopps int
    208  1.39   aymeric grfioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
    209   1.1        mw {
    210  1.11    chopps 	struct grf_softc *gp;
    211   1.1        mw 	int error;
    212   1.1        mw 
    213  1.11    chopps 	gp = grfsp[GRFUNIT(dev)];
    214   1.1        mw 	error = 0;
    215  1.11    chopps 
    216   1.1        mw 	switch (cmd) {
    217   1.5        mw 	case OGRFIOCGINFO:
    218   1.5        mw 	        /* argl.. no bank-member.. */
    219   1.5        mw 	  	bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo)-4);
    220   1.5        mw 		break;
    221   1.1        mw 	case GRFIOCGINFO:
    222   1.1        mw 		bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo));
    223   1.1        mw 		break;
    224   1.1        mw 	case GRFIOCON:
    225   1.1        mw 		error = grfon(dev);
    226   1.1        mw 		break;
    227   1.1        mw 	case GRFIOCOFF:
    228   1.1        mw 		error = grfoff(dev);
    229   1.1        mw 		break;
    230   1.1        mw 	case GRFIOCSINFO:
    231  1.11    chopps 		error = grfsinfo(dev, (struct grfdyninfo *) data);
    232   1.1        mw 		break;
    233   1.3        mw 	case GRFGETVMODE:
    234  1.26     veego 		return(gp->g_mode(gp, GM_GRFGETVMODE, data, 0, 0));
    235   1.3        mw 	case GRFSETVMODE:
    236  1.26     veego 		error = gp->g_mode(gp, GM_GRFSETVMODE, data, 0, 0);
    237  1.18    chopps 		if (error == 0 && gp->g_itedev && !(gp->g_flags & GF_GRFON))
    238  1.11    chopps 			ite_reinit(gp->g_itedev);
    239   1.3        mw 		break;
    240   1.3        mw 	case GRFGETNUMVM:
    241  1.26     veego 		return(gp->g_mode(gp, GM_GRFGETNUMVM, data, 0, 0));
    242  1.11    chopps 	/*
    243  1.11    chopps 	 * these are all hardware dependant, and have to be resolved
    244  1.11    chopps 	 * in the respective driver.
    245  1.11    chopps 	 */
    246   1.5        mw 	case GRFIOCPUTCMAP:
    247   1.5        mw 	case GRFIOCGETCMAP:
    248   1.5        mw 	case GRFIOCSSPRITEPOS:
    249   1.5        mw 	case GRFIOCGSPRITEPOS:
    250   1.5        mw 	case GRFIOCSSPRITEINF:
    251   1.5        mw 	case GRFIOCGSPRITEINF:
    252   1.5        mw 	case GRFIOCGSPRITEMAX:
    253  1.18    chopps 	case GRFIOCBITBLT:
    254  1.20    chopps     	case GRFIOCSETMON:
    255  1.17    chopps 	case GRFTOGGLE: /* Toggles between Cirrus boards and native ECS on
    256  1.17    chopps                      Amiga. 15/11/94 ill */
    257  1.22    chopps 		/*
    258  1.22    chopps 		 * We need the minor dev number to get the overlay/image
    259  1.22    chopps 		 * information for grf_ul.
    260  1.22    chopps 		 */
    261  1.26     veego 		return(gp->g_mode(gp, GM_GRFIOCTL, data, cmd, dev));
    262  1.27        is 
    263  1.34        is 	case GRFIOCBLANK:	/* blank ioctl, IOCON/OFF will turn ite on */
    264  1.27        is 	case FBIOSVIDEO:
    265  1.34        is 		error = gp->g_mode(gp, GM_GRFIOCTL, data, GRFIOCBLANK, dev);
    266  1.34        is 		if (!error)
    267  1.34        is 			gp->g_blank = *(int *)data;
    268  1.34        is 		return (error);
    269  1.34        is 
    270  1.34        is 	case FBIOGVIDEO:
    271  1.34        is 		*(int *)data = gp->g_blank;
    272  1.34        is 		return (0);
    273  1.27        is 
    274   1.1        mw 	default:
    275  1.21    chopps #if NVIEW > 0
    276  1.11    chopps 		/*
    277  1.11    chopps 		 * check to see whether it's a command recognized by the
    278  1.11    chopps 		 * view code if the unit is 0
    279  1.39   aymeric 		 * XXX
    280  1.11    chopps 		 */
    281  1.42   gehenna 		if (GRFUNIT(dev) == 0) {
    282  1.42   gehenna 			extern const struct cdevsw view_cdevsw;
    283  1.42   gehenna 
    284  1.42   gehenna 			return((*view_cdevsw.d_ioctl)(dev, cmd, data, flag, p));
    285  1.42   gehenna 		}
    286  1.21    chopps #endif
    287  1.41    atatat 		error = EPASSTHROUGH;
    288   1.1        mw 		break;
    289   1.1        mw 
    290   1.1        mw 	}
    291   1.1        mw 	return(error);
    292   1.1        mw }
    293   1.1        mw 
    294   1.1        mw /*ARGSUSED*/
    295  1.11    chopps int
    296  1.39   aymeric grfpoll(dev_t dev, int events, struct proc *p)
    297   1.1        mw {
    298  1.30    mhitch 	return(events & (POLLOUT | POLLWRNORM));
    299   1.1        mw }
    300   1.1        mw 
    301  1.11    chopps /*
    302  1.39   aymeric  * map the contents of a graphics display card into process'
    303  1.11    chopps  * memory space.
    304  1.11    chopps  */
    305  1.35    simonb paddr_t
    306  1.39   aymeric grfmmap(dev_t dev, off_t off, int prot)
    307   1.1        mw {
    308  1.11    chopps 	struct grf_softc *gp;
    309  1.11    chopps 	struct grfinfo *gi;
    310  1.39   aymeric 
    311  1.11    chopps 	gp = grfsp[GRFUNIT(dev)];
    312  1.11    chopps 	gi = &gp->g_display;
    313   1.1        mw 
    314  1.39   aymeric 	/*
    315  1.11    chopps 	 * control registers
    316  1.11    chopps 	 */
    317  1.11    chopps 	if (off >= 0 && off < gi->gd_regsize)
    318  1.35    simonb 		return(((paddr_t)gi->gd_regaddr + off) >> PGSHIFT);
    319   1.1        mw 
    320  1.11    chopps 	/*
    321  1.11    chopps 	 * frame buffer
    322  1.11    chopps 	 */
    323  1.11    chopps 	if (off >= gi->gd_regsize && off < gi->gd_regsize+gi->gd_fbsize) {
    324  1.11    chopps 		off -= gi->gd_regsize;
    325  1.35    simonb 		return(((paddr_t)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.39   aymeric grfon(dev_t dev)
    333   1.1        mw {
    334  1.11    chopps 	struct grf_softc *gp;
    335   1.1        mw 
    336  1.11    chopps 	gp = grfsp[GRFUNIT(dev)];
    337   1.1        mw 
    338   1.3        mw 	if (gp->g_flags & GF_GRFON)
    339  1.11    chopps 		return(0);
    340  1.11    chopps 
    341   1.3        mw 	gp->g_flags |= GF_GRFON;
    342  1.11    chopps 	if (gp->g_itedev != NODEV)
    343  1.11    chopps 		ite_off(gp->g_itedev, 3);
    344   1.3        mw 
    345  1.26     veego 	return(gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVON : GM_GRFON,
    346  1.26     veego 							NULL, 0, 0));
    347   1.1        mw }
    348   1.1        mw 
    349  1.11    chopps int
    350  1.39   aymeric grfoff(dev_t dev)
    351   1.1        mw {
    352  1.11    chopps 	struct grf_softc *gp;
    353   1.1        mw 	int error;
    354   1.3        mw 
    355  1.11    chopps 	gp = grfsp[GRFUNIT(dev)];
    356  1.11    chopps 
    357  1.11    chopps 	if ((gp->g_flags & GF_GRFON) == 0)
    358  1.11    chopps 		return(0);
    359  1.11    chopps 
    360   1.3        mw 	gp->g_flags &= ~GF_GRFON;
    361  1.26     veego 	error = gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF,
    362  1.26     veego 							NULL, 0, 0);
    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.39   aymeric grfsinfo(dev_t dev, struct grfdyninfo *dyninfo)
    375   1.1        mw {
    376  1.11    chopps 	struct grf_softc *gp;
    377   1.1        mw 	int error;
    378   1.1        mw 
    379  1.11    chopps 	gp = grfsp[GRFUNIT(dev)];
    380  1.26     veego 	error = gp->g_mode(gp, GM_GRFCONFIG, dyninfo, 0, 0);
    381   1.1        mw 
    382  1.11    chopps 	/*
    383  1.11    chopps 	 * Closely tied together no X's
    384  1.11    chopps 	 */
    385  1.11    chopps 	if (gp->g_itedev != NODEV)
    386  1.11    chopps 		ite_reinit(gp->g_itedev);
    387   1.1        mw 	return(error);
    388   1.1        mw }
    389   1.1        mw 
    390   1.1        mw #endif	/* NGRF > 0 */
    391