Home | History | Annotate | Line # | Download | only in dev
zbus.c revision 1.18
      1  1.18       is /*	$NetBSD: zbus.c,v 1.18 1996/05/09 20:31:47 is Exp $	*/
      2   1.1   chopps 
      3   1.1   chopps /*
      4   1.1   chopps  * Copyright (c) 1994 Christian E. Hopps
      5   1.1   chopps  * All rights reserved.
      6   1.1   chopps  *
      7   1.1   chopps  * Redistribution and use in source and binary forms, with or without
      8   1.1   chopps  * modification, are permitted provided that the following conditions
      9   1.1   chopps  * are met:
     10   1.1   chopps  * 1. Redistributions of source code must retain the above copyright
     11   1.1   chopps  *    notice, this list of conditions and the following disclaimer.
     12   1.1   chopps  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1   chopps  *    notice, this list of conditions and the following disclaimer in the
     14   1.1   chopps  *    documentation and/or other materials provided with the distribution.
     15   1.1   chopps  * 3. All advertising materials mentioning features or use of this software
     16   1.1   chopps  *    must display the following acknowledgement:
     17   1.1   chopps  *      This product includes software developed by Christian E. Hopps.
     18   1.1   chopps  * 4. The name of the author may not be used to endorse or promote products
     19   1.1   chopps  *    derived from this software without specific prior written permission
     20   1.1   chopps  *
     21   1.1   chopps  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22   1.1   chopps  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23   1.1   chopps  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24   1.1   chopps  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25   1.1   chopps  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26   1.1   chopps  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27   1.1   chopps  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28   1.1   chopps  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29   1.1   chopps  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30   1.1   chopps  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1   chopps  */
     32   1.1   chopps #include <sys/param.h>
     33   1.1   chopps #include <sys/device.h>
     34  1.14    veego #include <sys/systm.h>
     35   1.1   chopps #include <machine/cpu.h>
     36   1.1   chopps #include <machine/pte.h>
     37   1.1   chopps #include <amiga/amiga/cfdev.h>
     38   1.1   chopps #include <amiga/amiga/device.h>
     39   1.1   chopps #include <amiga/dev/zbusvar.h>
     40   1.1   chopps 
     41   1.1   chopps struct aconfdata {
     42   1.1   chopps 	char *name;
     43   1.1   chopps 	int manid;
     44   1.1   chopps 	int prodid;
     45   1.1   chopps };
     46   1.1   chopps 
     47   1.1   chopps struct preconfdata {
     48   1.1   chopps 	int manid;
     49   1.1   chopps 	int prodid;
     50   1.1   chopps 	caddr_t vaddr;
     51   1.1   chopps };
     52   1.1   chopps 
     53   1.1   chopps 
     54   1.1   chopps /*
     55   1.1   chopps  * explain the names.. 0123456789 => zothfisven
     56   1.1   chopps  */
     57   1.1   chopps static struct aconfdata aconftab[] = {
     58   1.1   chopps 	/* Commodore Amiga */
     59   1.6   chopps 	{ "atfsc",	514,	84 },
     60   1.1   chopps 	{ "atzee",	513,	1 },
     61   1.1   chopps 	{ "atzsc",	514,	3 },
     62  1.13   chopps 	{ "bah",	514,	9 },	/* A2060 */
     63   1.1   chopps 	{ "le",		514,	112 },
     64   1.1   chopps 	{ "ql",		514,	69 },
     65   1.1   chopps 	{ "ql",		514,	70 },
     66   1.1   chopps 	/* Ameristar */
     67   1.1   chopps 	{ "le",		1053,	1 },
     68  1.13   chopps 	{ "bah",	1053,	9 },	/* A2060 */
     69   1.3   chopps 	{ "es",		1053,	10 },
     70  1.13   chopps 	/* University of Lowell */
     71   1.9   chopps 	{ "grful",	1030,	0 },
     72   1.1   chopps 	/* Macrosystems */
     73   1.1   chopps 	{ "grfrt",	18260,	6 },
     74   1.3   chopps 	{ "grfrh",	18260,	16},	/* Retina BLT Z3 */
     75  1.15       is 	{ "grfrh",	18260,	19},	/* Altais */
     76   1.1   chopps 	/* Greater valley products */
     77   1.1   chopps 	{ "gvpbus",	2017,	2 },
     78   1.1   chopps 	{ "gvpbus",	2017,	11 },
     79   1.1   chopps 	{ "giv",	2017,	32 },
     80   1.5   chopps 	{ "gio",	2017,	255 },
     81   1.1   chopps 	/* progressive perhiperals */
     82   1.1   chopps 	{ "zssc",	2026,	150 },
     83   1.1   chopps 	{ "ppia",	2026,	187 },
     84   1.1   chopps 	{ "ppta",	2026,	105 },
     85   1.1   chopps 	{ "ppha",	2026,	1 },
     86   1.1   chopps 	{ "mrsc",	2026,	0 },
     87   1.1   chopps 	/* CSA */
     88   1.1   chopps 	{ "mgnsc",	1058,	17 },
     89   1.1   chopps 	{ "otgsc",	1058,	21 },
     90   1.1   chopps 	/* Microbotics */
     91   1.1   chopps 	{ "vhzsc",	1010,	69 },
     92   1.1   chopps 	/* Supra */
     93   1.1   chopps 	{ "wstsc",	1056,	12 },
     94   1.6   chopps 	{ "wstsc",	1056,	13 },
     95   1.1   chopps 	/* IVS */
     96   1.6   chopps 	{ "itrmp",	2112,	48 },
     97   1.1   chopps 	{ "itrmp",	2112,	52 },
     98   1.1   chopps 	{ "ivasc",	2112,	242 },
     99   1.1   chopps 	{ "ivsc",	2112,	243 },
    100   1.1   chopps 	/* Hydra */
    101   1.1   chopps 	{ "ed",		2121,	1 },
    102   1.1   chopps 	/* ASDG */
    103   1.1   chopps 	{ "ed",		9999,	9 },		/* XXXX */
    104   1.7   chopps 	/* Village Tronic Ariadne */
    105   1.7   chopps 	{ "ae",		2167,	201},
    106   1.1   chopps 	/* bsc/Alf Data */
    107   1.1   chopps 	{ "mfc",	2092,	16 },
    108   1.1   chopps 	{ "mfc",	2092,	17 },
    109   1.1   chopps 	{ "mfc",	2092,	18 },
    110   1.1   chopps 	/* Cirrus CL GD 5426 -> Picasso, Piccolo, EGS Spectrum */
    111   1.1   chopps 	{ "grfcl",	2167,	11},	/* Picasso-II mem*/
    112   1.1   chopps 	{ "grfcl",	2167,	12},	/* regs */
    113   1.3   chopps 	{ "grfcl",	2193,	2},	/* Spectrum mem */
    114   1.3   chopps 	{ "grfcl",	2193,	1},	/* Spectrum regs */
    115   1.3   chopps 	{ "grfcl",	2195,	5},	/* Piccolo mem */
    116   1.3   chopps 	{ "grfcl",	2195,	6},	/* Piccolo regs */
    117   1.1   chopps 	/* MacroSystemsUS */
    118   1.1   chopps 	{ "wesc",	2203,	19},	/* Warp engine */
    119  1.10   chopps 	/* phase 5 digital products */
    120  1.10   chopps 	{ "flmem",	8512,	10},	/* FastlaneZ3 memory */
    121  1.10   chopps 	{ "flsc",	8512,	11},	/* FastlaneZ3 */
    122  1.12   chopps 	{ "grfcv",	8512,	34},	/* CyberVison 64 */
    123   1.1   chopps 	/* Commodore Amiga */
    124   1.3   chopps 	{ "afsc",	514,	84},	/* A4091 SCSI HD Controller */
    125   1.3   chopps 	/* Hacker Inc. */
    126  1.11   chopps 	{ "mlhsc",	2011,	1 },
    127  1.11   chopps 	/* Resource Management Force */
    128  1.17       is 	{ "qn",		2011,	2 },	/* QuickNet Ethernet */
    129  1.17       is 	/* ??? */
    130  1.17       is 	{ "empsc",	2171,	21 }	/* Emplant SCSI */
    131   1.1   chopps };
    132   1.1   chopps static int naconfent = sizeof(aconftab) / sizeof(struct aconfdata);
    133   1.1   chopps 
    134   1.1   chopps /*
    135   1.1   chopps  * Anything listed in this table is subject to pre-configuration,
    136   1.1   chopps  * if autoconf.c:config_console() calls amiga_config_found() on
    137   1.1   chopps  * the Zorro III device.
    138   1.1   chopps  */
    139   1.1   chopps static struct preconfdata preconftab[] = {
    140  1.15       is 	{18260, 6, 0 },	/* Retina Z2 */
    141  1.15       is 	{18260, 16, 0}, /* Retina BLT Z3 */
    142  1.15       is 	{18260, 19, 0}, /* Altais */
    143   1.4   chopps 	{2167,	11, 0},	/* Picasso-II mem*/
    144   1.4   chopps 	{2167,	12, 0},	/* regs */
    145   1.4   chopps 	{2193,	2, 0},	/* Spectrum mem */
    146   1.4   chopps 	{2193,	1, 0},	/* Spectrum regs */
    147   1.4   chopps 	{2195,	5, 0},	/* Piccolo mem */
    148   1.8   chopps 	{2195,	6, 0},	/* Piccolo regs */
    149  1.14    veego 	{1030,	0, 0},	/* Ulwl board */
    150  1.14    veego 	{8512,	34, 0}	/* Cybervison 64 */
    151   1.1   chopps };
    152   1.1   chopps static int npreconfent = sizeof(preconftab) / sizeof(struct preconfdata);
    153   1.1   chopps 
    154   1.1   chopps 
    155   1.1   chopps void zbusattach __P((struct device *, struct device *, void *));
    156   1.1   chopps int zbusprint __P((void *, char *));
    157  1.16  thorpej int zbusmatch __P((struct device *, void *, void *));
    158   1.1   chopps caddr_t zbusmap __P((caddr_t, u_int));
    159   1.1   chopps static char *aconflookup __P((int, int));
    160   1.1   chopps 
    161   1.1   chopps /*
    162   1.1   chopps  * given a manufacturer id and product id, find the name
    163   1.1   chopps  * that describes this board.
    164   1.1   chopps  */
    165   1.1   chopps static char *
    166   1.1   chopps aconflookup(mid, pid)
    167   1.1   chopps 	int mid, pid;
    168   1.1   chopps {
    169   1.1   chopps 	struct aconfdata *adp, *eadp;
    170   1.1   chopps 
    171   1.1   chopps 	eadp = &aconftab[naconfent];
    172   1.1   chopps 	for (adp = aconftab; adp < eadp; adp++)
    173   1.1   chopps 		if (adp->manid == mid && adp->prodid == pid)
    174   1.1   chopps 			return(adp->name);
    175   1.1   chopps 	return("board");
    176   1.1   chopps }
    177   1.1   chopps 
    178   1.1   chopps /*
    179   1.1   chopps  * mainbus driver
    180   1.1   chopps  */
    181  1.16  thorpej 
    182  1.16  thorpej struct cfattach zbus_ca = {
    183  1.16  thorpej 	sizeof(struct device), zbusmatch, zbusattach
    184  1.16  thorpej };
    185  1.16  thorpej 
    186  1.16  thorpej struct cfdriver zbus_cd = {
    187  1.16  thorpej 	NULL, "zbus", DV_DULL, NULL, 0
    188   1.1   chopps };
    189   1.1   chopps 
    190   1.1   chopps static struct cfdata *early_cfdata;
    191   1.1   chopps 
    192   1.1   chopps /*ARGSUSED*/
    193   1.1   chopps int
    194  1.16  thorpej zbusmatch(pdp, match, auxp)
    195   1.1   chopps 	struct device *pdp;
    196  1.16  thorpej 	void *match, *auxp;
    197   1.1   chopps {
    198  1.16  thorpej 	struct cfdata *cfp = match;
    199  1.16  thorpej 
    200   1.1   chopps 	if (matchname(auxp, "zbus") == 0)
    201   1.1   chopps 		return(0);
    202   1.1   chopps 	if (amiga_realconfig == 0)
    203   1.1   chopps 		early_cfdata = cfp;
    204   1.1   chopps 	return(1);
    205   1.1   chopps }
    206   1.1   chopps 
    207   1.1   chopps /*
    208   1.1   chopps  * called to attach bus, we probe, i.e., scan configdev structs passed
    209   1.1   chopps  * in, for each found name call config_found() which will do this again
    210   1.1   chopps  * with that driver if matched else print a diag.
    211   1.1   chopps  */
    212   1.1   chopps void
    213   1.1   chopps zbusattach(pdp, dp, auxp)
    214   1.1   chopps 	struct device *pdp, *dp;
    215   1.1   chopps 	void *auxp;
    216   1.1   chopps {
    217   1.1   chopps 	struct zbus_args za;
    218   1.1   chopps 	struct preconfdata *pcp, *epcp;
    219   1.1   chopps 	struct cfdev *cdp, *ecdp;
    220   1.1   chopps 
    221   1.1   chopps 	epcp = &preconftab[npreconfent];
    222   1.1   chopps 	ecdp = &cfdev[ncfdev];
    223   1.1   chopps 	if (amiga_realconfig) {
    224   1.1   chopps 		if (ZTWOMEMADDR)
    225  1.14    veego 			printf(": mem 0x%08lx-0x%08lx",
    226   1.1   chopps 			    ZTWOMEMADDR, ZTWOMEMADDR + NBPG * NZTWOMEMPG - 1);
    227   1.1   chopps 		if (ZBUSAVAIL)
    228   1.1   chopps 			printf (": i/o size 0x%08x", ZBUSAVAIL);
    229   1.1   chopps 		printf("\n");
    230   1.1   chopps 	}
    231   1.1   chopps 	for (cdp = cfdev; cdp < ecdp; cdp++) {
    232   1.1   chopps 		for (pcp = preconftab; pcp < epcp; pcp++) {
    233   1.1   chopps 			if (pcp->manid == cdp->rom.manid &&
    234   1.1   chopps 			    pcp->prodid == cdp->rom.prodid)
    235   1.1   chopps 				break;
    236   1.1   chopps 		}
    237   1.1   chopps 		if (amiga_realconfig == 0 && pcp >= epcp)
    238   1.1   chopps 			continue;
    239   1.1   chopps 
    240   1.1   chopps 		/*
    241   1.1   chopps 		 * check if it's a Zorro II or III board and not linked into
    242   1.1   chopps 		 * MemList (i.e. not a memory board)
    243   1.1   chopps 		 */
    244   1.1   chopps 		if ((cdp->rom.type & 0xe0) != 0xc0 &&
    245   1.1   chopps 		    (cdp->rom.type & 0xe0) != 0x80)
    246   1.1   chopps 			continue;	/* er_Type != Zorro I/O */
    247   1.1   chopps 
    248   1.1   chopps 		za.pa = cdp->addr;
    249   1.1   chopps 		za.size = cdp->size;
    250   1.1   chopps 		if (amiga_realconfig && pcp < epcp && pcp->vaddr)
    251   1.1   chopps 			za.va = pcp->vaddr;
    252   1.1   chopps 		else {
    253  1.18       is 			za.va = (void *) (isztwopa(za.pa) ? ztwomap(za.pa)
    254  1.18       is 			    : zbusmap(za.pa, za.size));
    255  1.18       is /*                     		??????? */
    256   1.1   chopps 			/*
    257   1.1   chopps 			 * save value if early console init
    258   1.1   chopps 			 */
    259   1.1   chopps 			if (amiga_realconfig == 0)
    260   1.1   chopps 				pcp->vaddr = za.va;
    261   1.1   chopps 		}
    262   1.1   chopps 		za.manid = cdp->rom.manid;
    263   1.1   chopps 		za.prodid = cdp->rom.prodid;
    264   1.1   chopps 		za.serno = cdp->rom.serno;
    265   1.1   chopps 		za.slot = (((u_long)za.pa >> 16) & 0xF) - 0x9;
    266   1.1   chopps 		amiga_config_found(early_cfdata, dp, &za, zbusprint);
    267   1.1   chopps 	}
    268   1.1   chopps }
    269   1.1   chopps 
    270   1.1   chopps /*
    271   1.1   chopps  * print configuration info.
    272   1.1   chopps  */
    273   1.1   chopps int
    274   1.1   chopps zbusprint(auxp, pnp)
    275   1.1   chopps 	void *auxp;
    276   1.1   chopps 	char *pnp;
    277   1.1   chopps {
    278   1.1   chopps 	struct zbus_args *zap;
    279   1.1   chopps 	int rv;
    280   1.1   chopps 
    281   1.1   chopps 	rv = UNCONF;
    282   1.1   chopps 	zap = auxp;
    283   1.1   chopps 
    284   1.1   chopps 	if (pnp) {
    285   1.1   chopps 		printf("%s at %s:", aconflookup(zap->manid, zap->prodid),
    286   1.1   chopps 		    pnp);
    287   1.1   chopps 		if (zap->manid == -1)
    288   1.1   chopps 			rv = UNSUPP;
    289   1.1   chopps 	}
    290  1.14    veego 	printf(" rom %p man/pro %d/%d", zap->pa, zap->manid, zap->prodid);
    291   1.1   chopps 	return(rv);
    292   1.1   chopps }
    293   1.1   chopps 
    294   1.1   chopps /*
    295  1.17       is  * this function is used to map Zorro physical I/O addresses into kernel
    296  1.17       is  * virtual addresses. We don't keep track which address we map where, we don't
    297  1.17       is  * NEED to know this. We made sure in amiga_init.c (by scanning all available
    298  1.17       is  * Zorro devices) to have enough kva-space available, so there is no extra
    299  1.17       is  * range check done here.
    300   1.1   chopps  */
    301   1.1   chopps caddr_t
    302   1.1   chopps zbusmap (pa, size)
    303   1.1   chopps 	caddr_t pa;
    304   1.1   chopps 	u_int size;
    305   1.1   chopps {
    306   1.1   chopps 	static vm_offset_t nextkva = 0;
    307   1.1   chopps 	vm_offset_t kva;
    308   1.1   chopps 
    309   1.1   chopps 	if (nextkva == 0)
    310   1.1   chopps 		nextkva = ZBUSADDR;
    311   1.1   chopps 
    312   1.1   chopps 	if (nextkva > ZBUSADDR + ZBUSAVAIL)
    313   1.1   chopps 		return 0;
    314   1.1   chopps 
    315   1.1   chopps 	/* size better be an integral multiple of the page size... */
    316   1.1   chopps 	kva = nextkva;
    317   1.1   chopps 	nextkva += size;
    318   1.1   chopps 	if (nextkva > ZBUSADDR + ZBUSAVAIL)
    319   1.1   chopps 		panic("allocating too much Zorro I/O address space");
    320   1.1   chopps 	physaccess((caddr_t)kva, (caddr_t)pa, size, PG_RW|PG_CI);
    321   1.1   chopps 	return((caddr_t)kva);
    322   1.1   chopps }
    323