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