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