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