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