Home | History | Annotate | Line # | Download | only in dev
zbus.c revision 1.4
      1 /*	$NetBSD: zbus.c,v 1.4 1995/04/23 16:20:47 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 	{2167,	11, 0},	/* Picasso-II mem*/
    129 	{2167,	12, 0},	/* regs */
    130 	{2193,	2, 0},	/* Spectrum mem */
    131 	{2193,	1, 0},	/* Spectrum regs */
    132 	{2195,	5, 0},	/* Piccolo mem */
    133 	{2195,	6, 0}	/* Piccolo regs */
    134 };
    135 static int npreconfent = sizeof(preconftab) / sizeof(struct preconfdata);
    136 
    137 
    138 void zbusattach __P((struct device *, struct device *, void *));
    139 int zbusprint __P((void *, char *));
    140 int zbusmatch __P((struct device *, struct cfdata *,void *));
    141 caddr_t zbusmap __P((caddr_t, u_int));
    142 static char *aconflookup __P((int, int));
    143 
    144 /*
    145  * given a manufacturer id and product id, find the name
    146  * that describes this board.
    147  */
    148 static char *
    149 aconflookup(mid, pid)
    150 	int mid, pid;
    151 {
    152 	struct aconfdata *adp, *eadp;
    153 
    154 	eadp = &aconftab[naconfent];
    155 	for (adp = aconftab; adp < eadp; adp++)
    156 		if (adp->manid == mid && adp->prodid == pid)
    157 			return(adp->name);
    158 	return("board");
    159 }
    160 
    161 /*
    162  * mainbus driver
    163  */
    164 struct cfdriver zbuscd = {
    165 	NULL, "zbus", (cfmatch_t)zbusmatch, zbusattach,
    166 	DV_DULL, sizeof(struct device), NULL, 0
    167 };
    168 
    169 static struct cfdata *early_cfdata;
    170 
    171 /*ARGSUSED*/
    172 int
    173 zbusmatch(pdp, cfp, auxp)
    174 	struct device *pdp;
    175 	struct cfdata *cfp;
    176 	void *auxp;
    177 {
    178 	if (matchname(auxp, "zbus") == 0)
    179 		return(0);
    180 	if (amiga_realconfig == 0)
    181 		early_cfdata = cfp;
    182 	return(1);
    183 }
    184 
    185 /*
    186  * called to attach bus, we probe, i.e., scan configdev structs passed
    187  * in, for each found name call config_found() which will do this again
    188  * with that driver if matched else print a diag.
    189  */
    190 void
    191 zbusattach(pdp, dp, auxp)
    192 	struct device *pdp, *dp;
    193 	void *auxp;
    194 {
    195 	struct zbus_args za;
    196 	struct preconfdata *pcp, *epcp;
    197 	struct cfdev *cdp, *ecdp;
    198 
    199 	epcp = &preconftab[npreconfent];
    200 	ecdp = &cfdev[ncfdev];
    201 	if (amiga_realconfig) {
    202 		if (ZTWOMEMADDR)
    203 			printf(": mem 0x%08x-0x%08x",
    204 			    ZTWOMEMADDR, ZTWOMEMADDR + NBPG * NZTWOMEMPG - 1);
    205 		if (ZBUSAVAIL)
    206 			printf (": i/o size 0x%08x", ZBUSAVAIL);
    207 		printf("\n");
    208 	}
    209 	for (cdp = cfdev; cdp < ecdp; cdp++) {
    210 		for (pcp = preconftab; pcp < epcp; pcp++) {
    211 			if (pcp->manid == cdp->rom.manid &&
    212 			    pcp->prodid == cdp->rom.prodid)
    213 				break;
    214 		}
    215 		if (amiga_realconfig == 0 && pcp >= epcp)
    216 			continue;
    217 
    218 		/*
    219 		 * check if it's a Zorro II or III board and not linked into
    220 		 * MemList (i.e. not a memory board)
    221 		 */
    222 		if ((cdp->rom.type & 0xe0) != 0xc0 &&
    223 		    (cdp->rom.type & 0xe0) != 0x80)
    224 			continue;	/* er_Type != Zorro I/O */
    225 
    226 		za.pa = cdp->addr;
    227 		za.size = cdp->size;
    228 		if (amiga_realconfig && pcp < epcp && pcp->vaddr)
    229 			za.va = pcp->vaddr;
    230 		else {
    231 			za.va = (void *) (isztwopa(za.pa) ? ztwomap(za.pa) :
    232 			    zbusmap(za.pa, za.size));
    233 /*                          ??????? */
    234 			/*
    235 			 * save value if early console init
    236 			 */
    237 			if (amiga_realconfig == 0)
    238 				pcp->vaddr = za.va;
    239 		}
    240 		za.manid = cdp->rom.manid;
    241 		za.prodid = cdp->rom.prodid;
    242 		za.serno = cdp->rom.serno;
    243 		za.slot = (((u_long)za.pa >> 16) & 0xF) - 0x9;
    244 		amiga_config_found(early_cfdata, dp, &za, zbusprint);
    245 	}
    246 }
    247 
    248 /*
    249  * print configuration info.
    250  */
    251 int
    252 zbusprint(auxp, pnp)
    253 	void *auxp;
    254 	char *pnp;
    255 {
    256 	struct zbus_args *zap;
    257 	int rv;
    258 
    259 	rv = UNCONF;
    260 	zap = auxp;
    261 
    262 	if (pnp) {
    263 		printf("%s at %s:", aconflookup(zap->manid, zap->prodid),
    264 		    pnp);
    265 		if (zap->manid == -1)
    266 			rv = UNSUPP;
    267 	}
    268 	printf(" rom 0x%x man/pro %d/%d", zap->pa, zap->manid, zap->prodid);
    269 	return(rv);
    270 }
    271 
    272 /*
    273  * this function is used to map Zorro physical I/O addresses into kernel virtual
    274  * addresses. We don't keep track which address we map where, we don't NEED
    275  * to know this. We made sure in amiga_init.c (by scanning all available Zorro
    276  * devices) to have enough kva-space available, so there is no extra range
    277  * check done here.
    278  */
    279 caddr_t
    280 zbusmap (pa, size)
    281 	caddr_t pa;
    282 	u_int size;
    283 {
    284 	static vm_offset_t nextkva = 0;
    285 	vm_offset_t kva;
    286 
    287 	if (nextkva == 0)
    288 		nextkva = ZBUSADDR;
    289 
    290 	if (nextkva > ZBUSADDR + ZBUSAVAIL)
    291 		return 0;
    292 
    293 	/* size better be an integral multiple of the page size... */
    294 	kva = nextkva;
    295 	nextkva += size;
    296 	if (nextkva > ZBUSADDR + ZBUSAVAIL)
    297 		panic("allocating too much Zorro I/O address space");
    298 	physaccess((caddr_t)kva, (caddr_t)pa, size, PG_RW|PG_CI);
    299 	return((caddr_t)kva);
    300 }
    301