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