Home | History | Annotate | Line # | Download | only in dev
zbus.c revision 1.39.4.1
      1 /*	$NetBSD: zbus.c,v 1.39.4.1 1999/07/01 23:01:45 thorpej 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 	{ "atzee",	513,	1 },
     60 	{ "atzsc",	514,	2 },
     61 	{ "atzsc",	514,	3 },
     62 	{ "bah",	514,	9 },	/* A2060 */
     63 	{ "ql",		514,	69 },
     64 	{ "ql",		514,	70 },
     65 	{ "atfsc",	514,	84 },
     66 	{ "le",		514,	112 },
     67 	/* Ameristar */
     68 	{ "le",		1053,	1 },
     69 	{ "bah",	1053,	9 },	/* A2060 */
     70 	{ "es",		1053,	10 },
     71 	/* University of Lowell */
     72 	{ "grful",	1030,	0 },
     73 	/* DMI */
     74 	{ "grfrs",	2129,	1 },	/* Resolver graphics board */
     75 	/* Macrosystems */
     76 	{ "grfrt",	18260,	6 },
     77 	{ "grfrh",	18260,	16},	/* Retina BLT Z3 */
     78 	{ "grfrh",	18260,	19},	/* Altais */
     79 	/* Greater valley products */
     80 	{ "gvpbus",	2017,	2 },
     81 	{ "gvpbus",	2017,	11 },
     82 	{ "giv",	2017,	32 },
     83 	{ "gio",	2017,	255 },
     84 	/* progressive perhiperals */
     85 	{ "zssc",	2026,	150 },
     86 	{ "ppia",	2026,	187 },
     87 	{ "ppta",	2026,	105 },
     88 	{ "ppha",	2026,	1 },
     89 	{ "mrsc",	2026,	0 },
     90 	/* CSA */
     91 	{ "mgnsc",	1058,	17 },
     92 	{ "otgsc",	1058,	21 },
     93 	/* Microbotics */
     94 	{ "vhzsc",	1010,	69 },
     95 	/* Supra */
     96 	{ "wstsc",	1056,	12 },
     97 	{ "wstsc",	1056,	13 },
     98 	/* IVS */
     99 	{ "itrmp",	2112,	48 },
    100 	{ "itrmp",	2112,	52 },
    101 	{ "ivasc",	2112,	242 },
    102 	{ "ivsc",	2112,	243 },
    103 	/* Hydra */
    104 	{ "ed",		2121,	1 },
    105 	/* ASDG */
    106 	{ "ed",		1023,	254 },
    107 	/* Village Tronic Ariadne */
    108 	{ "le",		2167,	201},
    109 	/* Village Tronic Ariadne II */
    110 	{ "ne",		2167,	202},
    111 	/* bsc/Alf Data */
    112 	{ "Tandem", 2092,    6 },	/* Tandem AT disk controler */
    113 	{ "mfc",	2092,	16 },
    114 	{ "mfc",	2092,	17 },
    115 	{ "mfc",	2092,	18 },
    116 	/* Cirrus CL GD 5426 -> Picasso, Piccolo, EGS Spectrum */
    117 	{ "grfcl",	2167,	11},	/* PicassoII mem */
    118 	{ "grfcl",	2167,	12},	/* PicassoII regs */
    119 	{ "grfcl",	2167,	21},	/* PicassoIV Z2 mem1 */
    120 	{ "grfcl",	2167,	22},	/* PicassoIV Z2 mem2 */
    121 	{ "grfcl",	2167,	23},	/* PicassoIV Z2 regs */
    122 	{ "grfcl",	2167,	24},	/* PicassoIV Z3 */
    123 	{ "grfcl",	2193,	2},	/* Spectrum mem */
    124 	{ "grfcl",	2193,	1},	/* Spectrum regs */
    125 	{ "grfcl",	2195,	5},	/* Piccolo mem */
    126 	{ "grfcl",	2195,	6},	/* Piccolo regs */
    127 	{ "grfcl",	2195,	10},	/* Piccolo SD64 mem */
    128 	{ "grfcl",	2195,	11},	/* Piccolo SD64 regs */
    129 	/* MacroSystemsUS */
    130 	{ "wesc",	2203,	19},	/* Warp engine */
    131 	/* phase 5 digital products */
    132 	{ "flmem",	8512,	10},	/* FastlaneZ3 memory */
    133 	{ "flsc",	8512,	11},	/* FastlaneZ3 */
    134 	{ "cbsc",	8512,	12},	/* Cyberstorm Mk I SCSI */
    135 	{ "bzivsc",	8512,	17},	/* Blizzard IV SCSI */
    136 	{ "bztzsc", 	8512,	24},	/* Blizzard 2060 SCSI */
    137 	{ "cbiisc", 	8512,	25},	/* Cyberstorm Mk II SCSI */
    138 	{ "grfcv",	8512,	34},	/* CyberVison 64 */
    139 	{ "grfcv3d",	8512,	67},	/* CyberVison 64/3D */
    140 	{ "cbiiisc", 	8512,	100},	/* Cyberstorm Mk III SCSI */
    141 	/* Hacker Inc. */
    142 	{ "mlhsc",	2011,	1 },
    143 	/* Resource Management Force */
    144 	{ "qn",		2011,	2 },	/* QuickNet Ethernet */
    145 	/* ??? */
    146 	{ "empsc",	2171,	21 },	/* Emplant SCSI */
    147 	{ "empsc",	2171,	32 },	/* Emplant SCSI */
    148 	/* Tseng ET4000 boards */
    149 	{ "grfet",	2117,	3 },	/* Merlin mem */
    150 	{ "grfet",	2117,	4 },	/* Merlin regs */
    151 	{ "grfet",	2167,	1 },	/* Domino mem */
    152 	{ "grfet",	2167,	2 },	/* Domino regs */
    153 	{ "grfet",	2167,	3 },	/* Domino regs (proto 16M) */
    154 	{ "grfet",	2181,	0 },	/* oMniBus */
    155 	/* Advanced Systems */
    156 	{ "nxsc",	2102,	1 },	/* Nexus SCSI board */
    157 	/* Masoboshi */
    158 	{ "mcsc",	8535,	4 },	/* Masoboshi Mastercard 702 */
    159 	/* Apollo */
    160 	{ "apssc",	8738,	35 },	/* Apollo '060 scsi */
    161 	/* KATO development */
    162 	{ "aumld",	2145,	128 },	/* Melody MPEG layer 2 audio board */
    163 	/* VMC Harald Frank */
    164 	{ "blst",	5001,	1},	/* ISDN Blaster */
    165 	{ "hyper4",	5001,	2},	/* Hypercom4-Zbus */
    166 	{ "hyper3",	5001,	3}	/* Hypercom3-Zbus */
    167 };
    168 static int naconfent = sizeof(aconftab) / sizeof(struct aconfdata);
    169 
    170 /*
    171  * Anything listed in this table is subject to pre-configuration,
    172  * if autoconf.c:config_console() calls amiga_config_found() on
    173  * the Zorro III device.
    174  */
    175 static struct preconfdata preconftab[] = {
    176 	{18260, 6, 0 },	/* Retina Z2 */			/* grf1 */
    177 	{18260, 16, 0}, /* Retina BLT Z3 */		/* grf2 */
    178 	{18260, 19, 0}, /* Altais */
    179 	{2167,	11, 0},	/* PicassoII mem */		/* grf3 */
    180 	{2167,	12, 0},	/* PicassoII regs */
    181 	{2167,	21, 0},	/* PicassoIV Z2 mem1 */
    182 	{2167,	22, 0},	/* PicassoIV Z2 mem2 */
    183 	{2167,	23, 0},	/* PicassoIV Z2 regs */
    184 	{2167,	24, 0},	/* PicassoIV Z3 */
    185 	{2193,	2, 0},	/* Spectrum mem */
    186 	{2193,	1, 0},	/* Spectrum regs */
    187 	{2195,	5, 0},	/* Piccolo mem */
    188 	{2195,	6, 0},	/* Piccolo regs */
    189 	{2195,	10, 0},	/* Piccolo SD64 mem */
    190 	{2195,	11, 0},	/* Piccolo SD64 regs */
    191 	{1030,	0, 0},	/* Ulwl board */		/* grf4 */
    192 	{8512,	34, 0},	/* Cybervison 64 */		/* grf5 */
    193 	{2117,	3, 0},	/* Merlin mem */		/* grf6 */
    194 	{2117,	4, 0},	/* Merlin regs */
    195 	{2167,	1, 0},	/* Domino mem */
    196 	{2167,	2, 0},	/* Domino regs */
    197 	{2167,	3, 0},	/* Domino regs (proto 16M) */
    198 	{2181,	0, 0},	/* oMniBus mem or regs */
    199 	{8512,	67, 0}	/* Cybervison 64/3D */		/* grf7 */
    200 };
    201 static int npreconfent = sizeof(preconftab) / sizeof(struct preconfdata);
    202 
    203 
    204 void zbusattach __P((struct device *, struct device *, void *));
    205 int zbusprint __P((void *, const char *));
    206 int zbusmatch __P((struct device *, struct cfdata *, void *));
    207 caddr_t zbusmap __P((caddr_t, u_int));
    208 static char *aconflookup __P((int, int));
    209 
    210 /*
    211  * given a manufacturer id and product id, find the name
    212  * that describes this board.
    213  */
    214 static char *
    215 aconflookup(mid, pid)
    216 	int mid, pid;
    217 {
    218 	struct aconfdata *adp, *eadp;
    219 
    220 	eadp = &aconftab[naconfent];
    221 	for (adp = aconftab; adp < eadp; adp++)
    222 		if (adp->manid == mid && adp->prodid == pid)
    223 			return(adp->name);
    224 	return("board");
    225 }
    226 
    227 /*
    228  * mainbus driver
    229  */
    230 
    231 struct cfattach zbus_ca = {
    232 	sizeof(struct device), zbusmatch, zbusattach
    233 };
    234 
    235 static struct cfdata *early_cfdata;
    236 
    237 /*ARGSUSED*/
    238 int
    239 zbusmatch(pdp, cfp, auxp)
    240 	struct device *pdp;
    241 	struct cfdata *cfp;
    242 	void *auxp;
    243 {
    244 
    245 	if (matchname(auxp, "zbus") == 0)
    246 		return(0);
    247 	if (amiga_realconfig == 0)
    248 		early_cfdata = cfp;
    249 	return(1);
    250 }
    251 
    252 /*
    253  * called to attach bus, we probe, i.e., scan configdev structs passed
    254  * in, for each found name call config_found() which will do this again
    255  * with that driver if matched else print a diag.
    256  */
    257 void
    258 zbusattach(pdp, dp, auxp)
    259 	struct device *pdp, *dp;
    260 	void *auxp;
    261 {
    262 	struct zbus_args za;
    263 	struct preconfdata *pcp, *epcp;
    264 	struct cfdev *cdp, *ecdp;
    265 
    266 	epcp = &preconftab[npreconfent];
    267 	ecdp = &cfdev[ncfdev];
    268 	if (amiga_realconfig) {
    269 		if (ZTWOMEMADDR)
    270 			printf(": mem 0x%08lx-0x%08lx",
    271 			    ZTWOMEMADDR, ZTWOMEMADDR + NBPG * NZTWOMEMPG - 1);
    272 		if (ZBUSAVAIL)
    273 			printf (": i/o size 0x%08x", ZBUSAVAIL);
    274 		printf("\n");
    275 	}
    276 	for (cdp = cfdev; cdp < ecdp; cdp++) {
    277 		for (pcp = preconftab; pcp < epcp; pcp++) {
    278 			if (pcp->manid == cdp->rom.manid &&
    279 			    pcp->prodid == cdp->rom.prodid)
    280 				break;
    281 		}
    282 		if (amiga_realconfig == 0 && pcp >= epcp)
    283 			continue;
    284 
    285 		/*
    286 		 * check if it's a Zorro II or III board and not linked into
    287 		 * MemList (i.e. not a memory board)
    288 		 */
    289 		if ((cdp->rom.type & 0xe0) != 0xc0 &&
    290 		    (cdp->rom.type & 0xe0) != 0x80)
    291 			continue;	/* er_Type != Zorro I/O */
    292 
    293 		za.pa = cdp->addr;
    294 		za.size = cdp->size;
    295 		if (amiga_realconfig && pcp < epcp && pcp->vaddr)
    296 			za.va = pcp->vaddr;
    297 		else {
    298 			za.va = (void *) (isztwopa(za.pa) ? ztwomap(za.pa)
    299 			    : zbusmap(za.pa, za.size));
    300 /*                     		??????? */
    301 			/*
    302 			 * save value if early console init
    303 			 */
    304 			if (amiga_realconfig == 0)
    305 				pcp->vaddr = za.va;
    306 		}
    307 		za.manid = cdp->rom.manid;
    308 		za.prodid = cdp->rom.prodid;
    309 		za.serno = cdp->rom.serno;
    310 		za.slot = (((u_long)za.pa >> 16) & 0xF) - 0x9;
    311 		amiga_config_found(early_cfdata, dp, &za, zbusprint);
    312 	}
    313 }
    314 
    315 /*
    316  * print configuration info.
    317  */
    318 int
    319 zbusprint(auxp, pnp)
    320 	void *auxp;
    321 	const char *pnp;
    322 {
    323 	struct zbus_args *zap;
    324 	int rv;
    325 
    326 	rv = UNCONF;
    327 	zap = auxp;
    328 
    329 	if (pnp) {
    330 		printf("%s at %s:", aconflookup(zap->manid, zap->prodid),
    331 		    pnp);
    332 		if (zap->manid == -1)
    333 			rv = UNSUPP;
    334 	}
    335 	printf(" pa %8p man/pro %d/%d", zap->pa, zap->manid, zap->prodid);
    336 	return(rv);
    337 }
    338 
    339 /*
    340  * this function is used to map Zorro physical I/O addresses into kernel
    341  * virtual addresses. We don't keep track which address we map where, we don't
    342  * NEED to know this. We made sure in amiga_init.c (by scanning all available
    343  * Zorro devices) to have enough kva-space available, so there is no extra
    344  * range check done here.
    345  */
    346 caddr_t
    347 zbusmap (pa, size)
    348 	caddr_t pa;
    349 	u_int size;
    350 {
    351 	static vm_offset_t nextkva = 0;
    352 	vm_offset_t kva;
    353 
    354 	if (nextkva == 0)
    355 		nextkva = ZBUSADDR;
    356 
    357 	if (nextkva > ZBUSADDR + ZBUSAVAIL)
    358 		return 0;
    359 
    360 	/* size better be an integral multiple of the page size... */
    361 	kva = nextkva;
    362 	nextkva += size;
    363 	if (nextkva > ZBUSADDR + ZBUSAVAIL)
    364 		panic("allocating too much Zorro I/O address space");
    365 	physaccess((caddr_t)kva, (caddr_t)pa, size, PG_RW|PG_CI);
    366 	return((caddr_t)kva);
    367 }
    368