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