zbus.c revision 1.75.20.1 1 /* $NetBSD: zbus.c,v 1.75.20.1 2021/05/13 00:47:23 thorpej 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.75.20.1 2021/05/13 00:47:23 thorpej 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 /* MNT */
197 { "mntva", 28014, 1} /* MNT VA2000 */
198 };
199 static int naconfent = sizeof(aconftab) / sizeof(struct aconfdata);
200
201 /*
202 * Anything listed in this table is subject to pre-configuration,
203 * if autoconf.c:config_console() calls amiga_config_found() on
204 * the Zorro III device.
205 */
206 static struct preconfdata preconftab[] = {
207 {18260, 6, 0 }, /* Retina Z2 */ /* grf1 */
208 {18260, 16, 0}, /* Retina BLT Z3 */ /* grf2 */
209 {18260, 19, 0}, /* Altais */
210 {2167, 11, 0}, /* PicassoII mem */ /* grf3 */
211 {2167, 12, 0}, /* PicassoII regs */
212 {2167, 21, 0}, /* PicassoIV Z2 mem1 */
213 {2167, 22, 0}, /* PicassoIV Z2 mem2 */
214 {2167, 23, 0}, /* PicassoIV Z2 regs */
215 {2167, 24, 0}, /* PicassoIV Z3 */
216 {2193, 2, 0}, /* Spectrum mem */
217 {2193, 1, 0}, /* Spectrum regs */
218 {2195, 5, 0}, /* Piccolo mem */
219 {2195, 6, 0}, /* Piccolo regs */
220 {2195, 10, 0}, /* Piccolo SD64 mem */
221 {2195, 11, 0}, /* Piccolo SD64 regs */
222 {1030, 0, 0}, /* Ulwl board */ /* grf4 */
223 {8512, 34, 0}, /* Cybervison 64 */ /* grf5 */
224 {2117, 3, 0}, /* Merlin mem */ /* grf6 */
225 {2117, 4, 0}, /* Merlin regs */
226 {2167, 1, 0}, /* Domino mem */
227 {2167, 2, 0}, /* Domino regs */
228 {2167, 3, 0}, /* Domino regs (proto 16M) */
229 {2181, 0, 0}, /* oMniBus mem or regs */
230 {8512, 67, 0} /* Cybervison 64/3D */ /* grf7 */
231 /* {28014, 1, 0} // MNTMN VA2000 */
232 };
233 static int npreconfent = sizeof(preconftab) / sizeof(struct preconfdata);
234
235 /*
236 * Quirks table.
237 */
238 #define ZORRO_QUIRK_NO_ZBUSMAP 1 /* Don't map VA=PA in zbusattach. */
239 static struct quirksdata quirkstab[] = {
240 {8512, 101, ZORRO_QUIRK_NO_ZBUSMAP}
241 };
242 static int nquirksent = sizeof(quirkstab) / sizeof(struct quirksdata);
243
244 void zbusattach(device_t, device_t, void *);
245 int zbusprint(void *, const char *);
246 int zbusmatch(device_t, cfdata_t, void *);
247 static const char *aconflookup(int, int);
248
249 /*
250 * given a manufacturer id and product id, find quirks
251 * for this board.
252 */
253
254 static uint8_t
255 quirkslookup(int mid, int pid)
256 {
257 const struct quirksdata *qdp, *eqdp;
258
259 eqdp = &quirkstab[nquirksent];
260 for (qdp = quirkstab; qdp < eqdp; qdp++)
261 if (qdp->manid == mid && qdp->prodid == pid)
262 return(qdp->quirks);
263 return(0);
264 }
265
266 /*
267 * given a manufacturer id and product id, find the name
268 * that describes this board.
269 */
270 static const char *
271 aconflookup(int mid, int pid)
272 {
273 const struct aconfdata *adp, *eadp;
274
275 eadp = &aconftab[naconfent];
276 for (adp = aconftab; adp < eadp; adp++)
277 if (adp->manid == mid && adp->prodid == pid)
278 return(adp->name);
279 return("board");
280 }
281
282 /*
283 * mainbus driver
284 */
285
286 CFATTACH_DECL_NEW(zbus, 0,
287 zbusmatch, zbusattach, NULL, NULL);
288
289 static cfdata_t early_cfdata;
290
291 /*ARGSUSED*/
292 int
293 zbusmatch(device_t parent, cfdata_t cf, void *aux)
294 {
295
296 if (matchname(aux, "zbus") == 0)
297 return(0);
298 if (amiga_realconfig == 0)
299 early_cfdata = cf;
300 return(1);
301 }
302
303 /*
304 * called to attach bus, we probe, i.e., scan configdev structs passed
305 * in, for each found name call config_found() which will do this again
306 * with that driver if matched else print a diag.
307 */
308 void
309 zbusattach(device_t parent, device_t self, void *aux)
310 {
311 struct zbus_args za;
312 struct preconfdata *pcp, *epcp;
313 struct cfdev *cdp, *ecdp;
314
315 epcp = &preconftab[npreconfent];
316 ecdp = &cfdev[ncfdev];
317 if (amiga_realconfig) {
318 if (ZTWOMEMADDR)
319 printf(": mem 0x%08lx-0x%08lx",
320 ZTWOMEMADDR,
321 ZTWOMEMADDR + PAGE_SIZE * NZTWOMEMPG - 1);
322 if (ZBUSAVAIL)
323 printf (": i/o size 0x%08x", ZBUSAVAIL);
324 printf("\n");
325 }
326 for (cdp = cfdev; cdp < ecdp; cdp++) {
327 for (pcp = preconftab; pcp < epcp; pcp++) {
328 if (pcp->manid == cdp->rom.manid &&
329 pcp->prodid == cdp->rom.prodid)
330 break;
331 }
332 if (amiga_realconfig == 0 && pcp >= epcp)
333 continue;
334
335 #if NZ3RAMBD > 0
336 if (z3rambd_match_id(cdp->rom.manid, cdp->rom.prodid) > 0)
337 { }
338 else
339 #endif /* NZ3RAMBD */
340 /*
341 * check if it's a Zorro II or III board and not linked into
342 * MemList (i.e. not a memory board)
343 */
344 switch (cdp->rom.type & (ERT_TYPEMASK | ERTF_MEMLIST)) {
345 case ERT_ZORROII:
346 case ERT_ZORROIII:
347 break;
348 default:
349 continue;
350 }
351
352 za.pa = cdp->addr;
353 za.size = cdp->size;
354 za.manid = cdp->rom.manid;
355 za.prodid = cdp->rom.prodid;
356 za.serno = cdp->rom.serno;
357 za.slot = (((u_long)za.pa >> 16) & 0xF) - 0x9;
358
359 if (amiga_realconfig && pcp < epcp && pcp->vaddr)
360 za.va = pcp->vaddr;
361 else {
362 if(quirkslookup(za.manid, za.prodid) !=
363 ZORRO_QUIRK_NO_ZBUSMAP)
364 za.va = (void *) (isztwopa(za.pa) ?
365 __UNVOLATILE(ztwomap(za.pa)) :
366 zbusmap(za.pa, za.size));
367 /*
368 * save value if early console init
369 */
370 if (amiga_realconfig == 0)
371 pcp->vaddr = za.va;
372 }
373 amiga_config_found(early_cfdata, self, &za, zbusprint,
374 CFARG_EOL);
375 }
376 }
377
378 /*
379 * print configuration info.
380 */
381 int
382 zbusprint(void *aux, const char *pnp)
383 {
384 struct zbus_args *zap;
385 int rv;
386
387 rv = UNCONF;
388 zap = aux;
389
390 if (pnp) {
391 aprint_normal("%s at %s:",
392 aconflookup(zap->manid, zap->prodid), pnp);
393 if (zap->manid == -1)
394 rv = UNSUPP;
395 }
396 aprint_normal(" pa %8p man/pro %d/%d", zap->pa, zap->manid,
397 zap->prodid);
398 return(rv);
399 }
400
401 /*
402 * this function is used to map Zorro physical I/O addresses into kernel
403 * virtual addresses. We don't keep track which address we map where, we don't
404 * NEED to know this. We made sure in amiga_init.c (by scanning all available
405 * Zorro devices) to have enough kva-space available, so there is no extra
406 * range check done here.
407 */
408 void *
409 zbusmap(void *pa, u_int size)
410 {
411 #if defined(__m68k__)
412 static vaddr_t nextkva = 0;
413 vaddr_t kva;
414
415 if (nextkva == 0)
416 nextkva = ZBUSADDR;
417
418 if (nextkva > ZBUSADDR + ZBUSAVAIL)
419 return 0;
420
421 /* size better be an integral multiple of the page size... */
422 kva = nextkva;
423 nextkva += size;
424 if (nextkva > ZBUSADDR + ZBUSAVAIL)
425 panic("allocating too much Zorro I/O address space");
426 physaccess((void *)kva, (void *)pa, size, PG_RW|PG_CI);
427 return((void *)kva);
428 #else
429 /*
430 * XXX we use direct constant mapping
431 */
432 return(pa);
433 #endif
434 }
435