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