Home | History | Annotate | Line # | Download | only in dev
grf.c revision 1.44
      1 /*	$NetBSD: grf.c,v 1.44 2002/10/02 04:55:49 thorpej 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.44 2002/10/02 04:55:49 thorpej 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 
     76 #include "view.h"
     77 #include "grf.h"
     78 
     79 #if NGRF > 0
     80 #include "ite.h"
     81 #if NITE == 0
     82 #define	ite_on(u,f)
     83 #define	ite_off(u,f)
     84 #define ite_reinit(d)
     85 #endif
     86 
     87 int grfon(dev_t);
     88 int grfoff(dev_t);
     89 int grfsinfo(dev_t, struct grfdyninfo *);
     90 
     91 void grfattach(struct device *, struct device *, void *);
     92 int grfmatch(struct device *, struct cfdata *, void *);
     93 int grfprint(void *, const char *);
     94 /*
     95  * pointers to grf drivers device structs
     96  */
     97 struct grf_softc *grfsp[NGRF];
     98 
     99 CFATTACH_DECL(grf, sizeof(struct device),
    100     grfmatch, grfattach, NULL, NULL);
    101 
    102 dev_type_open(grfopen);
    103 dev_type_close(grfclose);
    104 dev_type_ioctl(grfioctl);
    105 dev_type_poll(grfpoll);
    106 dev_type_mmap(grfmmap);
    107 
    108 const struct cdevsw grf_cdevsw = {
    109 	grfopen, grfclose, nullread, nullwrite, grfioctl,
    110 	nostop, notty, grfpoll, grfmmap,
    111 };
    112 
    113 /*
    114  * only used in console init.
    115  */
    116 static struct cfdata *cfdata;
    117 
    118 /*
    119  * match if the unit of grf matches its perspective
    120  * low level board driver.
    121  */
    122 int
    123 grfmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
    124 {
    125 
    126 	if (cfp->cf_unit != ((struct grf_softc *)pdp)->g_unit)
    127 		return(0);
    128 	cfdata = cfp;
    129 	return(1);
    130 }
    131 
    132 /*
    133  * attach.. plug pointer in and print some info.
    134  * then try and attach an ite to us. note: dp is NULL
    135  * durring console init.
    136  */
    137 void
    138 grfattach(struct device *pdp, struct device *dp, void *auxp)
    139 {
    140 	struct grf_softc *gp;
    141 	int maj;
    142 
    143 	gp = (struct grf_softc *)pdp;
    144 	grfsp[gp->g_unit] = (struct grf_softc *)pdp;
    145 
    146 	/*
    147 	 * find our major device number
    148 	 */
    149 	maj = cdevsw_lookup_major(&grf_cdevsw);
    150 
    151 	gp->g_grfdev = makedev(maj, gp->g_unit);
    152 	if (dp != NULL) {
    153 		printf(": width %d height %d", gp->g_display.gd_dwidth,
    154 		    gp->g_display.gd_dheight);
    155 		if (gp->g_display.gd_colors == 2)
    156 			printf(" monochrome\n");
    157 		else
    158 			printf(" colors %d\n", gp->g_display.gd_colors);
    159 	}
    160 
    161 	/*
    162 	 * try and attach an ite
    163 	 */
    164 	amiga_config_found(cfdata, dp, gp, grfprint);
    165 }
    166 
    167 int
    168 grfprint(void *auxp, const char *pnp)
    169 {
    170 	if (pnp)
    171 		printf("ite at %s", pnp);
    172 	return(UNCONF);
    173 }
    174 
    175 /*ARGSUSED*/
    176 int
    177 grfopen(dev_t dev, int flags, int devtype, struct proc *p)
    178 {
    179 	struct grf_softc *gp;
    180 
    181 	if (GRFUNIT(dev) >= NGRF || (gp = grfsp[GRFUNIT(dev)]) == NULL)
    182 		return(ENXIO);
    183 
    184 	if ((gp->g_flags & GF_ALIVE) == 0)
    185 		return(ENXIO);
    186 
    187 	if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
    188 		return(EBUSY);
    189 
    190 	return(0);
    191 }
    192 
    193 /*ARGSUSED*/
    194 int
    195 grfclose(dev_t dev, int flags, int mode, struct proc *p)
    196 {
    197 	struct grf_softc *gp;
    198 
    199 	gp = grfsp[GRFUNIT(dev)];
    200 	(void)grfoff(dev);
    201 	gp->g_flags &= GF_ALIVE;
    202 	return(0);
    203 }
    204 
    205 /*ARGSUSED*/
    206 int
    207 grfioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
    208 {
    209 	struct grf_softc *gp;
    210 	int error;
    211 
    212 	gp = grfsp[GRFUNIT(dev)];
    213 	error = 0;
    214 
    215 	switch (cmd) {
    216 	case OGRFIOCGINFO:
    217 	        /* argl.. no bank-member.. */
    218 	  	bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo)-4);
    219 		break;
    220 	case GRFIOCGINFO:
    221 		bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo));
    222 		break;
    223 	case GRFIOCON:
    224 		error = grfon(dev);
    225 		break;
    226 	case GRFIOCOFF:
    227 		error = grfoff(dev);
    228 		break;
    229 	case GRFIOCSINFO:
    230 		error = grfsinfo(dev, (struct grfdyninfo *) data);
    231 		break;
    232 	case GRFGETVMODE:
    233 		return(gp->g_mode(gp, GM_GRFGETVMODE, data, 0, 0));
    234 	case GRFSETVMODE:
    235 		error = gp->g_mode(gp, GM_GRFSETVMODE, data, 0, 0);
    236 		if (error == 0 && gp->g_itedev && !(gp->g_flags & GF_GRFON))
    237 			ite_reinit(gp->g_itedev);
    238 		break;
    239 	case GRFGETNUMVM:
    240 		return(gp->g_mode(gp, GM_GRFGETNUMVM, data, 0, 0));
    241 	/*
    242 	 * these are all hardware dependant, and have to be resolved
    243 	 * in the respective driver.
    244 	 */
    245 	case GRFIOCPUTCMAP:
    246 	case GRFIOCGETCMAP:
    247 	case GRFIOCSSPRITEPOS:
    248 	case GRFIOCGSPRITEPOS:
    249 	case GRFIOCSSPRITEINF:
    250 	case GRFIOCGSPRITEINF:
    251 	case GRFIOCGSPRITEMAX:
    252 	case GRFIOCBITBLT:
    253     	case GRFIOCSETMON:
    254 	case GRFTOGGLE: /* Toggles between Cirrus boards and native ECS on
    255                      Amiga. 15/11/94 ill */
    256 		/*
    257 		 * We need the minor dev number to get the overlay/image
    258 		 * information for grf_ul.
    259 		 */
    260 		return(gp->g_mode(gp, GM_GRFIOCTL, data, cmd, dev));
    261 
    262 	case GRFIOCBLANK:	/* blank ioctl, IOCON/OFF will turn ite on */
    263 	case FBIOSVIDEO:
    264 		error = gp->g_mode(gp, GM_GRFIOCTL, data, GRFIOCBLANK, dev);
    265 		if (!error)
    266 			gp->g_blank = *(int *)data;
    267 		return (error);
    268 
    269 	case FBIOGVIDEO:
    270 		*(int *)data = gp->g_blank;
    271 		return (0);
    272 
    273 	default:
    274 #if NVIEW > 0
    275 		/*
    276 		 * check to see whether it's a command recognized by the
    277 		 * view code if the unit is 0
    278 		 * XXX
    279 		 */
    280 		if (GRFUNIT(dev) == 0) {
    281 			extern const struct cdevsw view_cdevsw;
    282 
    283 			return((*view_cdevsw.d_ioctl)(dev, cmd, data, flag, p));
    284 		}
    285 #endif
    286 		error = EPASSTHROUGH;
    287 		break;
    288 
    289 	}
    290 	return(error);
    291 }
    292 
    293 /*ARGSUSED*/
    294 int
    295 grfpoll(dev_t dev, int events, struct proc *p)
    296 {
    297 	return(events & (POLLOUT | POLLWRNORM));
    298 }
    299 
    300 /*
    301  * map the contents of a graphics display card into process'
    302  * memory space.
    303  */
    304 paddr_t
    305 grfmmap(dev_t dev, off_t off, int prot)
    306 {
    307 	struct grf_softc *gp;
    308 	struct grfinfo *gi;
    309 
    310 	gp = grfsp[GRFUNIT(dev)];
    311 	gi = &gp->g_display;
    312 
    313 	/*
    314 	 * control registers
    315 	 */
    316 	if (off >= 0 && off < gi->gd_regsize)
    317 		return(((paddr_t)gi->gd_regaddr + off) >> PGSHIFT);
    318 
    319 	/*
    320 	 * frame buffer
    321 	 */
    322 	if (off >= gi->gd_regsize && off < gi->gd_regsize+gi->gd_fbsize) {
    323 		off -= gi->gd_regsize;
    324 		return(((paddr_t)gi->gd_fbaddr + off) >> PGSHIFT);
    325 	}
    326 	/* bogus */
    327 	return(-1);
    328 }
    329 
    330 int
    331 grfon(dev_t dev)
    332 {
    333 	struct grf_softc *gp;
    334 
    335 	gp = grfsp[GRFUNIT(dev)];
    336 
    337 	if (gp->g_flags & GF_GRFON)
    338 		return(0);
    339 
    340 	gp->g_flags |= GF_GRFON;
    341 	if (gp->g_itedev != NODEV)
    342 		ite_off(gp->g_itedev, 3);
    343 
    344 	return(gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVON : GM_GRFON,
    345 							NULL, 0, 0));
    346 }
    347 
    348 int
    349 grfoff(dev_t dev)
    350 {
    351 	struct grf_softc *gp;
    352 	int error;
    353 
    354 	gp = grfsp[GRFUNIT(dev)];
    355 
    356 	if ((gp->g_flags & GF_GRFON) == 0)
    357 		return(0);
    358 
    359 	gp->g_flags &= ~GF_GRFON;
    360 	error = gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF,
    361 							NULL, 0, 0);
    362 
    363 	/*
    364 	 * Closely tied together no X's
    365 	 */
    366 	if (gp->g_itedev != NODEV)
    367 		ite_on(gp->g_itedev, 2);
    368 
    369 	return(error);
    370 }
    371 
    372 int
    373 grfsinfo(dev_t dev, struct grfdyninfo *dyninfo)
    374 {
    375 	struct grf_softc *gp;
    376 	int error;
    377 
    378 	gp = grfsp[GRFUNIT(dev)];
    379 	error = gp->g_mode(gp, GM_GRFCONFIG, dyninfo, 0, 0);
    380 
    381 	/*
    382 	 * Closely tied together no X's
    383 	 */
    384 	if (gp->g_itedev != NODEV)
    385 		ite_reinit(gp->g_itedev);
    386 	return(error);
    387 }
    388 
    389 #endif	/* NGRF > 0 */
    390