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