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