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