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