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