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