Home | History | Annotate | Line # | Download | only in dev
zbus.c revision 1.17
      1 /*	$NetBSD: zbus.c,v 1.17 1996/03/28 18:41:49 is 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 #include <sys/param.h>
     33 #include <sys/device.h>
     34 #include <sys/systm.h>
     35 #include <machine/cpu.h>
     36 #include <machine/pte.h>
     37 #include <amiga/amiga/cfdev.h>
     38 #include <amiga/amiga/device.h>
     39 #include <amiga/dev/zbusvar.h>
     40 
     41 struct aconfdata {
     42 	char *name;
     43 	int manid;
     44 	int prodid;
     45 };
     46 
     47 struct preconfdata {
     48 	int manid;
     49 	int prodid;
     50 	caddr_t vaddr;
     51 };
     52 
     53 
     54 /*
     55  * explain the names.. 0123456789 => zothfisven
     56  */
     57 static struct aconfdata aconftab[] = {
     58 	/* Commodore Amiga */
     59 	{ "atfsc",	514,	84 },
     60 	{ "atzee",	513,	1 },
     61 	{ "atzsc",	514,	3 },
     62 	{ "bah",	514,	9 },	/* A2060 */
     63 	{ "le",		514,	112 },
     64 	{ "ql",		514,	69 },
     65 	{ "ql",		514,	70 },
     66 	/* Ameristar */
     67 	{ "le",		1053,	1 },
     68 	{ "bah",	1053,	9 },	/* A2060 */
     69 	{ "es",		1053,	10 },
     70 	/* University of Lowell */
     71 	{ "grful",	1030,	0 },
     72 	/* Macrosystems */
     73 	{ "grfrt",	18260,	6 },
     74 	{ "grfrh",	18260,	16},	/* Retina BLT Z3 */
     75 	{ "grfrh",	18260,	19},	/* Altais */
     76 	/* Greater valley products */
     77 	{ "gvpbus",	2017,	2 },
     78 	{ "gvpbus",	2017,	11 },
     79 	{ "giv",	2017,	32 },
     80 	{ "gio",	2017,	255 },
     81 	/* progressive perhiperals */
     82 	{ "zssc",	2026,	150 },
     83 	{ "ppia",	2026,	187 },
     84 	{ "ppta",	2026,	105 },
     85 	{ "ppha",	2026,	1 },
     86 	{ "mrsc",	2026,	0 },
     87 	/* CSA */
     88 	{ "mgnsc",	1058,	17 },
     89 	{ "otgsc",	1058,	21 },
     90 	/* Microbotics */
     91 	{ "vhzsc",	1010,	69 },
     92 	/* Supra */
     93 	{ "wstsc",	1056,	12 },
     94 	{ "wstsc",	1056,	13 },
     95 	/* IVS */
     96 	{ "itrmp",	2112,	48 },
     97 	{ "itrmp",	2112,	52 },
     98 	{ "ivasc",	2112,	242 },
     99 	{ "ivsc",	2112,	243 },
    100 	/* Hydra */
    101 	{ "ed",		2121,	1 },
    102 	/* ASDG */
    103 	{ "ed",		9999,	9 },		/* XXXX */
    104 	/* Village Tronic Ariadne */
    105 	{ "ae",		2167,	201},
    106 	/* bsc/Alf Data */
    107 	{ "mfc",	2092,	16 },
    108 	{ "mfc",	2092,	17 },
    109 	{ "mfc",	2092,	18 },
    110 	/* Cirrus CL GD 5426 -> Picasso, Piccolo, EGS Spectrum */
    111 	{ "grfcl",	2167,	11},	/* Picasso-II mem*/
    112 	{ "grfcl",	2167,	12},	/* regs */
    113 	{ "grfcl",	2193,	2},	/* Spectrum mem */
    114 	{ "grfcl",	2193,	1},	/* Spectrum regs */
    115 	{ "grfcl",	2195,	5},	/* Piccolo mem */
    116 	{ "grfcl",	2195,	6},	/* Piccolo regs */
    117 	/* MacroSystemsUS */
    118 	{ "wesc",	2203,	19},	/* Warp engine */
    119 	/* phase 5 digital products */
    120 	{ "flmem",	8512,	10},	/* FastlaneZ3 memory */
    121 	{ "flsc",	8512,	11},	/* FastlaneZ3 */
    122 	{ "grfcv",	8512,	34},	/* CyberVison 64 */
    123 	/* Commodore Amiga */
    124 	{ "afsc",	514,	84},	/* A4091 SCSI HD Controller */
    125 	/* Hacker Inc. */
    126 	{ "mlhsc",	2011,	1 },
    127 	/* Resource Management Force */
    128 	{ "qn",		2011,	2 },	/* QuickNet Ethernet */
    129 	/* ??? */
    130 	{ "empsc",	2171,	21 }	/* Emplant SCSI */
    131 };
    132 static int naconfent = sizeof(aconftab) / sizeof(struct aconfdata);
    133 
    134 /*
    135  * Anything listed in this table is subject to pre-configuration,
    136  * if autoconf.c:config_console() calls amiga_config_found() on
    137  * the Zorro III device.
    138  */
    139 static struct preconfdata preconftab[] = {
    140 	{18260, 6, 0 },	/* Retina Z2 */
    141 	{18260, 16, 0}, /* Retina BLT Z3 */
    142 	{18260, 19, 0}, /* Altais */
    143 	{2167,	11, 0},	/* Picasso-II mem*/
    144 	{2167,	12, 0},	/* regs */
    145 	{2193,	2, 0},	/* Spectrum mem */
    146 	{2193,	1, 0},	/* Spectrum regs */
    147 	{2195,	5, 0},	/* Piccolo mem */
    148 	{2195,	6, 0},	/* Piccolo regs */
    149 	{1030,	0, 0},	/* Ulwl board */
    150 	{8512,	34, 0}	/* Cybervison 64 */
    151 };
    152 static int npreconfent = sizeof(preconftab) / sizeof(struct preconfdata);
    153 
    154 
    155 void zbusattach __P((struct device *, struct device *, void *));
    156 int zbusprint __P((void *, char *));
    157 int zbusmatch __P((struct device *, void *, void *));
    158 caddr_t zbusmap __P((caddr_t, u_int));
    159 static char *aconflookup __P((int, int));
    160 
    161 /*
    162  * given a manufacturer id and product id, find the name
    163  * that describes this board.
    164  */
    165 static char *
    166 aconflookup(mid, pid)
    167 	int mid, pid;
    168 {
    169 	struct aconfdata *adp, *eadp;
    170 
    171 	eadp = &aconftab[naconfent];
    172 	for (adp = aconftab; adp < eadp; adp++)
    173 		if (adp->manid == mid && adp->prodid == pid)
    174 			return(adp->name);
    175 	return("board");
    176 }
    177 
    178 /*
    179  * mainbus driver
    180  */
    181 
    182 struct cfattach zbus_ca = {
    183 	sizeof(struct device), zbusmatch, zbusattach
    184 };
    185 
    186 struct cfdriver zbus_cd = {
    187 	NULL, "zbus", DV_DULL, NULL, 0
    188 };
    189 
    190 static struct cfdata *early_cfdata;
    191 
    192 /*ARGSUSED*/
    193 int
    194 zbusmatch(pdp, match, auxp)
    195 	struct device *pdp;
    196 	void *match, *auxp;
    197 {
    198 	struct cfdata *cfp = match;
    199 
    200 	if (matchname(auxp, "zbus") == 0)
    201 		return(0);
    202 	if (amiga_realconfig == 0)
    203 		early_cfdata = cfp;
    204 	return(1);
    205 }
    206 
    207 /*
    208  * called to attach bus, we probe, i.e., scan configdev structs passed
    209  * in, for each found name call config_found() which will do this again
    210  * with that driver if matched else print a diag.
    211  */
    212 void
    213 zbusattach(pdp, dp, auxp)
    214 	struct device *pdp, *dp;
    215 	void *auxp;
    216 {
    217 	struct zbus_args za;
    218 	struct preconfdata *pcp, *epcp;
    219 	struct cfdev *cdp, *ecdp;
    220 
    221 	epcp = &preconftab[npreconfent];
    222 	ecdp = &cfdev[ncfdev];
    223 	if (amiga_realconfig) {
    224 		if (ZTWOMEMADDR)
    225 			printf(": mem 0x%08lx-0x%08lx",
    226 			    ZTWOMEMADDR, ZTWOMEMADDR + NBPG * NZTWOMEMPG - 1);
    227 		if (ZBUSAVAIL)
    228 			printf (": i/o size 0x%08x", ZBUSAVAIL);
    229 		printf("\n");
    230 	}
    231 	for (cdp = cfdev; cdp < ecdp; cdp++) {
    232 		for (pcp = preconftab; pcp < epcp; pcp++) {
    233 			if (pcp->manid == cdp->rom.manid &&
    234 			    pcp->prodid == cdp->rom.prodid)
    235 				break;
    236 		}
    237 		if (amiga_realconfig == 0 && pcp >= epcp)
    238 			continue;
    239 
    240 		/*
    241 		 * check if it's a Zorro II or III board and not linked into
    242 		 * MemList (i.e. not a memory board)
    243 		 */
    244 		if ((cdp->rom.type & 0xe0) != 0xc0 &&
    245 		    (cdp->rom.type & 0xe0) != 0x80)
    246 			continue;	/* er_Type != Zorro I/O */
    247 
    248 		za.pa = cdp->addr;
    249 		za.size = cdp->size;
    250 		if (amiga_realconfig && pcp < epcp && pcp->vaddr)
    251 			za.va = pcp->vaddr;
    252 		else {
    253 			za.va = (void *) (isztwopa(za.pa) ? ztwomap(za.pa) :
    254 			    zbusmap(za.pa, za.size));
    255 /*                          ??????? */
    256 			/*
    257 			 * save value if early console init
    258 			 */
    259 			if (amiga_realconfig == 0)
    260 				pcp->vaddr = za.va;
    261 		}
    262 		za.manid = cdp->rom.manid;
    263 		za.prodid = cdp->rom.prodid;
    264 		za.serno = cdp->rom.serno;
    265 		za.slot = (((u_long)za.pa >> 16) & 0xF) - 0x9;
    266 		amiga_config_found(early_cfdata, dp, &za, zbusprint);
    267 	}
    268 }
    269 
    270 /*
    271  * print configuration info.
    272  */
    273 int
    274 zbusprint(auxp, pnp)
    275 	void *auxp;
    276 	char *pnp;
    277 {
    278 	struct zbus_args *zap;
    279 	int rv;
    280 
    281 	rv = UNCONF;
    282 	zap = auxp;
    283 
    284 	if (pnp) {
    285 		printf("%s at %s:", aconflookup(zap->manid, zap->prodid),
    286 		    pnp);
    287 		if (zap->manid == -1)
    288 			rv = UNSUPP;
    289 	}
    290 	printf(" rom %p man/pro %d/%d", zap->pa, zap->manid, zap->prodid);
    291 	return(rv);
    292 }
    293 
    294 /*
    295  * this function is used to map Zorro physical I/O addresses into kernel
    296  * virtual addresses. We don't keep track which address we map where, we don't
    297  * NEED to know this. We made sure in amiga_init.c (by scanning all available
    298  * Zorro devices) to have enough kva-space available, so there is no extra
    299  * range check done here.
    300  */
    301 caddr_t
    302 zbusmap (pa, size)
    303 	caddr_t pa;
    304 	u_int size;
    305 {
    306 	static vm_offset_t nextkva = 0;
    307 	vm_offset_t kva;
    308 
    309 	if (nextkva == 0)
    310 		nextkva = ZBUSADDR;
    311 
    312 	if (nextkva > ZBUSADDR + ZBUSAVAIL)
    313 		return 0;
    314 
    315 	/* size better be an integral multiple of the page size... */
    316 	kva = nextkva;
    317 	nextkva += size;
    318 	if (nextkva > ZBUSADDR + ZBUSAVAIL)
    319 		panic("allocating too much Zorro I/O address space");
    320 	physaccess((caddr_t)kva, (caddr_t)pa, size, PG_RW|PG_CI);
    321 	return((caddr_t)kva);
    322 }
    323