Home | History | Annotate | Line # | Download | only in dev
grf_cc.c revision 1.28
      1  1.28       mrg /*	$NetBSD: grf_cc.c,v 1.28 2000/06/29 08:44:05 mrg Exp $	*/
      2   1.8    chopps 
      3  1.17    chopps /*
      4  1.17    chopps  * Copyright (c) 1994 Christian E. Hopps
      5  1.17    chopps  * All rights reserved.
      6  1.17    chopps  *
      7  1.17    chopps  * Redistribution and use in source and binary forms, with or without
      8  1.17    chopps  * modification, are permitted provided that the following conditions
      9  1.17    chopps  * are met:
     10  1.17    chopps  * 1. Redistributions of source code must retain the above copyright
     11  1.17    chopps  *    notice, this list of conditions and the following disclaimer.
     12  1.17    chopps  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.17    chopps  *    notice, this list of conditions and the following disclaimer in the
     14  1.17    chopps  *    documentation and/or other materials provided with the distribution.
     15  1.17    chopps  * 3. All advertising materials mentioning features or use of this software
     16  1.17    chopps  *    must display the following acknowledgement:
     17  1.17    chopps  *      This product includes software developed by Christian E. Hopps.
     18  1.17    chopps  * 4. The name of the author may not be used to endorse or promote products
     19  1.17    chopps  *    derived from this software without specific prior written permission
     20  1.17    chopps  *
     21  1.17    chopps  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.17    chopps  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.17    chopps  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.17    chopps  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.17    chopps  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.17    chopps  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.17    chopps  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.17    chopps  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.17    chopps  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.17    chopps  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.17    chopps  */
     32  1.14    chopps #include "grfcc.h"
     33  1.14    chopps #if NGRFCC > 0
     34  1.12    chopps /*
     35  1.12    chopps  * currently this is a backward compat hack that interface to
     36  1.12    chopps  * view.c
     37  1.12    chopps  */
     38   1.6        mw 
     39   1.9    chopps #include <sys/param.h>
     40  1.19     veego #include <sys/proc.h>
     41   1.9    chopps #include <sys/errno.h>
     42   1.9    chopps #include <sys/ioctl.h>
     43  1.10    chopps #include <sys/queue.h>
     44  1.12    chopps #include <sys/device.h>
     45  1.19     veego #include <sys/systm.h>
     46   1.9    chopps #include <machine/cpu.h>
     47  1.12    chopps #include <amiga/amiga/color.h>	/* DEBUG */
     48  1.12    chopps #include <amiga/amiga/device.h>
     49   1.9    chopps #include <amiga/amiga/custom.h>
     50   1.9    chopps #include <amiga/amiga/cia.h>
     51   1.9    chopps #include <amiga/dev/grfioctl.h>
     52   1.9    chopps #include <amiga/dev/grfvar.h>
     53   1.9    chopps #include <amiga/dev/grf_ccreg.h>
     54   1.9    chopps #include <amiga/dev/grfabs_reg.h>
     55   1.9    chopps #include <amiga/dev/viewioctl.h>
     56   1.4        mw 
     57  1.19     veego #include <sys/conf.h>
     58  1.19     veego #include <machine/conf.h>
     59  1.26       mrg 
     60  1.25    mhitch #include <uvm/uvm_extern.h>
     61  1.19     veego 
     62  1.19     veego #include "view.h"
     63  1.12    chopps 
     64  1.23     veego int grfccmatch __P((struct device *, struct cfdata *, void *));
     65  1.20       cgd int grfccprint __P((void *, const char *));
     66  1.12    chopps void grfccattach __P((struct device *, struct device *, void *));
     67  1.12    chopps void grf_cc_on __P((struct grf_softc *));
     68  1.12    chopps 
     69  1.18   thorpej struct cfattach grfcc_ca = {
     70  1.18   thorpej 	sizeof(struct grf_softc), grfccmatch, grfccattach
     71  1.18   thorpej };
     72  1.12    chopps 
     73  1.12    chopps /*
     74  1.12    chopps  * only used in console init
     75  1.12    chopps  */
     76  1.12    chopps static struct cfdata *cfdata;
     77  1.12    chopps 
     78  1.12    chopps /*
     79  1.12    chopps  * we make sure to only init things once.  this is somewhat
     80  1.12    chopps  * tricky regarding the console.
     81   1.1        mw  */
     82  1.12    chopps int
     83  1.23     veego grfccmatch(pdp, cfp, auxp)
     84  1.12    chopps 	struct device *pdp;
     85  1.23     veego 	struct cfdata *cfp;
     86  1.23     veego 	void *auxp;
     87   1.1        mw {
     88  1.12    chopps 	static int ccconunit = -1;
     89  1.12    chopps 	char *mainbus_name = auxp;
     90   1.6        mw 
     91  1.12    chopps 	/*
     92  1.12    chopps 	 * allow only one cc console
     93  1.12    chopps 	 */
     94  1.12    chopps 	if (amiga_realconfig == 0 && ccconunit != -1)
     95  1.12    chopps 		return(0);
     96  1.12    chopps 	if (matchname("grfcc", mainbus_name) == 0)
     97  1.12    chopps 		return(0);
     98  1.12    chopps 	if (amiga_realconfig == 0 || ccconunit != cfp->cf_unit) {
     99  1.12    chopps 		if (grfcc_probe() == 0)
    100  1.12    chopps 			return(0);
    101  1.12    chopps 		viewprobe();
    102  1.12    chopps 		/*
    103  1.12    chopps 		 * XXX nasty hack. opens view[0] and never closes.
    104  1.12    chopps 		 */
    105  1.19     veego 		if (viewopen(0, 0, 0, NULL))
    106  1.12    chopps 			return(0);
    107  1.12    chopps 		if (amiga_realconfig == 0) {
    108  1.12    chopps 			ccconunit = cfp->cf_unit;
    109  1.12    chopps 			cfdata = cfp;
    110  1.12    chopps 		}
    111  1.12    chopps 	}
    112  1.12    chopps 	return(1);
    113   1.1        mw }
    114   1.1        mw 
    115  1.12    chopps /*
    116  1.12    chopps  * attach to the grfbus (mainbus)
    117  1.12    chopps  */
    118  1.12    chopps void
    119  1.12    chopps grfccattach(pdp, dp, auxp)
    120  1.12    chopps 	struct device *pdp, *dp;
    121  1.12    chopps 	void *auxp;
    122   1.1        mw {
    123  1.12    chopps 	static struct grf_softc congrf;
    124  1.12    chopps 	struct grf_softc *gp;
    125   1.1        mw 
    126  1.12    chopps 	if (dp == NULL)
    127  1.12    chopps 		gp = &congrf;
    128  1.12    chopps 	else
    129  1.12    chopps 		gp = (struct grf_softc *)dp;
    130  1.12    chopps 
    131  1.12    chopps 	if (dp != NULL && congrf.g_regkva != 0) {
    132  1.12    chopps 		/*
    133  1.12    chopps 		 * we inited earlier just copy the info
    134  1.12    chopps 		 * take care not to copy the device struct though.
    135  1.12    chopps 		 */
    136  1.12    chopps 		bcopy(&congrf.g_display, &gp->g_display,
    137  1.12    chopps 		    (char *)&gp[1] - (char *)&gp->g_display);
    138  1.12    chopps 	} else {
    139  1.12    chopps 		gp->g_unit = GRF_CC_UNIT;
    140  1.13    chopps 		gp->g_flags = GF_ALIVE;
    141  1.12    chopps 		gp->g_mode = cc_mode;
    142  1.12    chopps 		gp->g_conpri = grfcc_cnprobe();
    143  1.12    chopps 		grfcc_iteinit(gp);
    144  1.12    chopps 		grf_cc_on(gp);
    145  1.12    chopps 	}
    146  1.12    chopps 	if (dp != NULL)
    147  1.22  christos 		printf("\n");
    148  1.12    chopps 	/*
    149  1.12    chopps 	 * attach grf
    150  1.12    chopps 	 */
    151  1.12    chopps 	amiga_config_found(cfdata, &gp->g_device, gp, grfccprint);
    152  1.12    chopps }
    153   1.1        mw 
    154  1.12    chopps int
    155  1.12    chopps grfccprint(auxp, pnp)
    156  1.12    chopps 	void *auxp;
    157  1.20       cgd 	const char *pnp;
    158  1.12    chopps {
    159  1.12    chopps 	if (pnp)
    160  1.22  christos 		printf("grf%d at %s", ((struct grf_softc *)auxp)->g_unit,
    161  1.12    chopps 			pnp);
    162  1.12    chopps 	return(UNCONF);
    163   1.1        mw }
    164   1.1        mw 
    165   1.1        mw /*
    166   1.1        mw  * Change the mode of the display.
    167   1.1        mw  * Right now all we can do is grfon/grfoff.
    168   1.1        mw  * Return a UNIX error number or 0 for success.
    169   1.1        mw  */
    170  1.12    chopps /*ARGSUSED*/
    171  1.12    chopps int
    172  1.12    chopps cc_mode(gp, cmd, arg, a2, a3)
    173  1.12    chopps 	struct grf_softc *gp;
    174  1.19     veego 	u_long cmd;
    175   1.1        mw 	void *arg;
    176  1.19     veego 	u_long a2;
    177  1.19     veego 	int a3;
    178   1.1        mw {
    179  1.19     veego 
    180  1.12    chopps 	switch (cmd) {
    181  1.12    chopps 	case GM_GRFON:
    182  1.12    chopps 		grf_cc_on(gp);
    183  1.12    chopps 		return(0);
    184  1.12    chopps 	case GM_GRFOFF:
    185  1.19     veego 		viewioctl(0, VIOCREMOVE, NULL, -1, NULL);
    186  1.12    chopps 		return(0);
    187  1.12    chopps 	case GM_GRFCONFIG:
    188  1.12    chopps 	default:
    189  1.12    chopps 		break;
    190  1.12    chopps 	}
    191  1.12    chopps 	return(EINVAL);
    192   1.1        mw }
    193   1.6        mw 
    194  1.12    chopps void
    195  1.12    chopps grf_cc_on(gp)
    196  1.12    chopps 	struct grf_softc *gp;
    197  1.12    chopps {
    198  1.12    chopps 	struct view_size vs;
    199  1.12    chopps 	bmap_t bm;
    200  1.12    chopps 	struct grfinfo *gi;
    201   1.6        mw 
    202  1.12    chopps 	gi = &gp->g_display;
    203   1.6        mw 
    204  1.19     veego 	viewioctl(0, VIOCGBMAP, (caddr_t)&bm, -1, NULL); /* XXX type of bm ? */
    205   1.6        mw 
    206  1.12    chopps 	gp->g_data = (caddr_t) 0xDeadBeaf; /* not particularly clean.. */
    207   1.6        mw 
    208  1.12    chopps 	gi->gd_regaddr = (caddr_t) 0xdff000;	/* depricated */
    209  1.12    chopps 	gi->gd_regsize = round_page(sizeof (custom));
    210  1.12    chopps 	gi->gd_fbaddr  = bm.hardware_address;
    211  1.12    chopps 	gi->gd_fbsize  = bm.depth*bm.bytes_per_row*bm.rows;
    212  1.12    chopps 
    213  1.19     veego 	if (viewioctl (0, VIOCGSIZE, (caddr_t)&vs, -1, NULL)) {
    214  1.19     veego 		/* XXX type of vs ? */
    215  1.12    chopps 		/* fill in some default values... XXX */
    216  1.12    chopps 		vs.width = 640;
    217  1.12    chopps 		vs.height = 400;
    218  1.12    chopps 		vs.depth = 2;
    219  1.12    chopps 	}
    220  1.12    chopps 	gi->gd_colors = 1 << vs.depth;
    221  1.12    chopps 	gi->gd_planes = vs.depth;
    222   1.6        mw 
    223  1.12    chopps 	gi->gd_fbwidth = vs.width;
    224  1.12    chopps 	gi->gd_fbheight = vs.height;
    225  1.12    chopps 	gi->gd_fbx = 0;
    226  1.12    chopps 	gi->gd_fby = 0;
    227  1.12    chopps 	gi->gd_dwidth = vs.width;
    228  1.12    chopps 	gi->gd_dheight = vs.height;
    229  1.12    chopps 	gi->gd_dx = 0;
    230  1.12    chopps 	gi->gd_dy = 0;
    231   1.6        mw 
    232  1.12    chopps 	gp->g_regkva = (void *)0xDeadBeaf;	/* builtin */
    233  1.12    chopps 	gp->g_fbkva = NULL;		/* not needed, view internal */
    234   1.1        mw 
    235  1.19     veego 	viewioctl(0, VIOCDISPLAY, NULL, -1, NULL);
    236  1.12    chopps }
    237   1.1        mw #endif
    238   1.4        mw 
    239