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