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