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