zbus.c revision 1.71 1 /* $NetBSD: zbus.c,v 1.71 2012/11/25 19:52:05 christos 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.71 2012/11/25 19:52:05 christos 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 parent, cfdata_t cf, void *aux)
288 {
289
290 if (matchname(aux, "zbus") == 0)
291 return(0);
292 if (amiga_realconfig == 0)
293 early_cfdata = cf;
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 parent, device_t self, void *aux)
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 switch (cdp->rom.type & (ERT_TYPEMASK | ERTF_MEMLIST)) {
334 case ERT_ZORROII:
335 case ERT_ZORROIII:
336 break;
337 default:
338 continue;
339 }
340
341 za.pa = cdp->addr;
342 za.size = cdp->size;
343 za.manid = cdp->rom.manid;
344 za.prodid = cdp->rom.prodid;
345 za.serno = cdp->rom.serno;
346 za.slot = (((u_long)za.pa >> 16) & 0xF) - 0x9;
347
348 if (amiga_realconfig && pcp < epcp && pcp->vaddr)
349 za.va = pcp->vaddr;
350 else {
351 if(quirkslookup(za.manid, za.prodid) !=
352 ZORRO_QUIRK_NO_ZBUSMAP)
353 za.va = (void *) (isztwopa(za.pa) ?
354 __UNVOLATILE(ztwomap(za.pa)) :
355 zbusmap(za.pa, za.size));
356 /*
357 * save value if early console init
358 */
359 if (amiga_realconfig == 0)
360 pcp->vaddr = za.va;
361 }
362 amiga_config_found(early_cfdata, self, &za, zbusprint);
363 }
364 }
365
366 /*
367 * print configuration info.
368 */
369 int
370 zbusprint(void *aux, const char *pnp)
371 {
372 struct zbus_args *zap;
373 int rv;
374
375 rv = UNCONF;
376 zap = aux;
377
378 if (pnp) {
379 aprint_normal("%s at %s:",
380 aconflookup(zap->manid, zap->prodid), pnp);
381 if (zap->manid == -1)
382 rv = UNSUPP;
383 }
384 aprint_normal(" pa %8p man/pro %d/%d", zap->pa, zap->manid,
385 zap->prodid);
386 return(rv);
387 }
388
389 /*
390 * this function is used to map Zorro physical I/O addresses into kernel
391 * virtual addresses. We don't keep track which address we map where, we don't
392 * NEED to know this. We made sure in amiga_init.c (by scanning all available
393 * Zorro devices) to have enough kva-space available, so there is no extra
394 * range check done here.
395 */
396 void *
397 zbusmap(void *pa, u_int size)
398 {
399 #if defined(__m68k__)
400 static vaddr_t nextkva = 0;
401 vaddr_t kva;
402
403 if (nextkva == 0)
404 nextkva = ZBUSADDR;
405
406 if (nextkva > ZBUSADDR + ZBUSAVAIL)
407 return 0;
408
409 /* size better be an integral multiple of the page size... */
410 kva = nextkva;
411 nextkva += size;
412 if (nextkva > ZBUSADDR + ZBUSAVAIL)
413 panic("allocating too much Zorro I/O address space");
414 physaccess((void *)kva, (void *)pa, size, PG_RW|PG_CI);
415 return((void *)kva);
416 #else
417 /*
418 * XXX we use direct constant mapping
419 */
420 return(pa);
421 #endif
422 }
423