zbus.c revision 1.31 1 /* $NetBSD: zbus.c,v 1.31 1997/01/06 18:05:15 is 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 { "ae", 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}, /* Picasso-II mem*/
116 { "grfcl", 2167, 12}, /* regs */
117 { "grfcl", 2193, 2}, /* Spectrum mem */
118 { "grfcl", 2193, 1}, /* Spectrum regs */
119 { "grfcl", 2195, 5}, /* Piccolo mem */
120 { "grfcl", 2195, 6}, /* Piccolo regs */
121 { "grfcl", 2195, 10}, /* Piccolo SD64 mem */
122 { "grfcl", 2195, 11}, /* Piccolo SD64 regs */
123 /* MacroSystemsUS */
124 { "wesc", 2203, 19}, /* Warp engine */
125 /* phase 5 digital products */
126 { "flmem", 8512, 10}, /* FastlaneZ3 memory */
127 { "flsc", 8512, 11}, /* FastlaneZ3 */
128 { "cbsc", 8512, 12}, /* Cyberstorm Mk I SCSI */
129 { "bzivsc", 8512, 17}, /* Blizzard IV SCSI */
130 { "bztzsc", 8512, 24}, /* Blizzard 2060 SCSI */
131 { "cbiisc", 8512, 25}, /* Cyberstorm Mk II SCSI */
132 { "grfcv", 8512, 34}, /* CyberVison 64 */
133 /* Hacker Inc. */
134 { "mlhsc", 2011, 1 },
135 /* Resource Management Force */
136 { "qn", 2011, 2 }, /* QuickNet Ethernet */
137 /* ??? */
138 { "empsc", 2171, 21 }, /* Emplant SCSI */
139 { "empsc", 2171, 32 }, /* Emplant SCSI */
140 /* Tseng ET4000 boards */
141 { "grfet", 2181, 0 }, /* oMniBus */
142 { "grfet", 2167, 1 }, /* Domnio mem */
143 { "grfet", 2167, 2 }, /* Domino regs */
144 { "grfet", 2117, 3 }, /* Merlin mem */
145 { "grfet", 2117, 4 }, /* Merlin regs */
146 /* Advanced Systems */
147 { "nxsc", 2102, 1 }, /* Nexus SCSI board */
148 /* Masoboshi */
149 { "mcsc", 8535, 4 }, /* Masoboshi Mastercard 702 */
150 /* Apollo */
151 { "apssc", 8738, 35 } /* Apollo '060 scsi */
152 };
153 static int naconfent = sizeof(aconftab) / sizeof(struct aconfdata);
154
155 /*
156 * Anything listed in this table is subject to pre-configuration,
157 * if autoconf.c:config_console() calls amiga_config_found() on
158 * the Zorro III device.
159 */
160 static struct preconfdata preconftab[] = {
161 {18260, 6, 0 }, /* Retina Z2 */
162 {18260, 16, 0}, /* Retina BLT Z3 */
163 {18260, 19, 0}, /* Altais */
164 {2167, 11, 0}, /* Picasso-II mem*/
165 {2167, 12, 0}, /* Picasso-II regs */
166 {2193, 2, 0}, /* Spectrum mem */
167 {2193, 1, 0}, /* Spectrum regs */
168 {2195, 5, 0}, /* Piccolo mem */
169 {2195, 6, 0}, /* Piccolo regs */
170 {2195, 10, 0}, /* Piccolo SD64 mem */
171 {2195, 11, 0}, /* Piccolo SD64 regs */
172 {1030, 0, 0}, /* Ulwl board */
173 {8512, 34, 0}, /* Cybervison 64 */
174 {8512, 34, 0}, /* Cybervison 64 */
175 {2181, 0, 0}, /* oMniBus mem or regs */
176 {2167, 1, 0}, /* Domino mem */
177 {2167, 2, 0}, /* Domino regs */
178 {2117, 3, 0}, /* Merlin mem */
179 {2117, 4, 0} /* Merlin regs */
180 };
181 static int npreconfent = sizeof(preconftab) / sizeof(struct preconfdata);
182
183
184 void zbusattach __P((struct device *, struct device *, void *));
185 int zbusprint __P((void *, const char *));
186 int zbusmatch __P((struct device *, struct cfdata *, void *));
187 caddr_t zbusmap __P((caddr_t, u_int));
188 static char *aconflookup __P((int, int));
189
190 /*
191 * given a manufacturer id and product id, find the name
192 * that describes this board.
193 */
194 static char *
195 aconflookup(mid, pid)
196 int mid, pid;
197 {
198 struct aconfdata *adp, *eadp;
199
200 eadp = &aconftab[naconfent];
201 for (adp = aconftab; adp < eadp; adp++)
202 if (adp->manid == mid && adp->prodid == pid)
203 return(adp->name);
204 return("board");
205 }
206
207 /*
208 * mainbus driver
209 */
210
211 struct cfattach zbus_ca = {
212 sizeof(struct device), zbusmatch, zbusattach
213 };
214
215 struct cfdriver zbus_cd = {
216 NULL, "zbus", DV_DULL, NULL, 0
217 };
218
219 static struct cfdata *early_cfdata;
220
221 /*ARGSUSED*/
222 int
223 zbusmatch(pdp, cfp, auxp)
224 struct device *pdp;
225 struct cfdata *cfp;
226 void *auxp;
227 {
228
229 if (matchname(auxp, "zbus") == 0)
230 return(0);
231 if (amiga_realconfig == 0)
232 early_cfdata = cfp;
233 return(1);
234 }
235
236 /*
237 * called to attach bus, we probe, i.e., scan configdev structs passed
238 * in, for each found name call config_found() which will do this again
239 * with that driver if matched else print a diag.
240 */
241 void
242 zbusattach(pdp, dp, auxp)
243 struct device *pdp, *dp;
244 void *auxp;
245 {
246 struct zbus_args za;
247 struct preconfdata *pcp, *epcp;
248 struct cfdev *cdp, *ecdp;
249
250 epcp = &preconftab[npreconfent];
251 ecdp = &cfdev[ncfdev];
252 if (amiga_realconfig) {
253 if (ZTWOMEMADDR)
254 printf(": mem 0x%08lx-0x%08lx",
255 ZTWOMEMADDR, ZTWOMEMADDR + NBPG * NZTWOMEMPG - 1);
256 if (ZBUSAVAIL)
257 printf (": i/o size 0x%08x", ZBUSAVAIL);
258 printf("\n");
259 }
260 for (cdp = cfdev; cdp < ecdp; cdp++) {
261 for (pcp = preconftab; pcp < epcp; pcp++) {
262 if (pcp->manid == cdp->rom.manid &&
263 pcp->prodid == cdp->rom.prodid)
264 break;
265 }
266 if (amiga_realconfig == 0 && pcp >= epcp)
267 continue;
268
269 /*
270 * check if it's a Zorro II or III board and not linked into
271 * MemList (i.e. not a memory board)
272 */
273 if ((cdp->rom.type & 0xe0) != 0xc0 &&
274 (cdp->rom.type & 0xe0) != 0x80)
275 continue; /* er_Type != Zorro I/O */
276
277 za.pa = cdp->addr;
278 za.size = cdp->size;
279 if (amiga_realconfig && pcp < epcp && pcp->vaddr)
280 za.va = pcp->vaddr;
281 else {
282 za.va = (void *) (isztwopa(za.pa) ? ztwomap(za.pa)
283 : zbusmap(za.pa, za.size));
284 /* ??????? */
285 /*
286 * save value if early console init
287 */
288 if (amiga_realconfig == 0)
289 pcp->vaddr = za.va;
290 }
291 za.manid = cdp->rom.manid;
292 za.prodid = cdp->rom.prodid;
293 za.serno = cdp->rom.serno;
294 za.slot = (((u_long)za.pa >> 16) & 0xF) - 0x9;
295 amiga_config_found(early_cfdata, dp, &za, zbusprint);
296 }
297 }
298
299 /*
300 * print configuration info.
301 */
302 int
303 zbusprint(auxp, pnp)
304 void *auxp;
305 const char *pnp;
306 {
307 struct zbus_args *zap;
308 int rv;
309
310 rv = UNCONF;
311 zap = auxp;
312
313 if (pnp) {
314 printf("%s at %s:", aconflookup(zap->manid, zap->prodid),
315 pnp);
316 if (zap->manid == -1)
317 rv = UNSUPP;
318 }
319 printf(" rom %p man/pro %d/%d", zap->pa, zap->manid, zap->prodid);
320 return(rv);
321 }
322
323 /*
324 * this function is used to map Zorro physical I/O addresses into kernel
325 * virtual addresses. We don't keep track which address we map where, we don't
326 * NEED to know this. We made sure in amiga_init.c (by scanning all available
327 * Zorro devices) to have enough kva-space available, so there is no extra
328 * range check done here.
329 */
330 caddr_t
331 zbusmap (pa, size)
332 caddr_t pa;
333 u_int size;
334 {
335 static vm_offset_t nextkva = 0;
336 vm_offset_t kva;
337
338 if (nextkva == 0)
339 nextkva = ZBUSADDR;
340
341 if (nextkva > ZBUSADDR + ZBUSAVAIL)
342 return 0;
343
344 /* size better be an integral multiple of the page size... */
345 kva = nextkva;
346 nextkva += size;
347 if (nextkva > ZBUSADDR + ZBUSAVAIL)
348 panic("allocating too much Zorro I/O address space");
349 physaccess((caddr_t)kva, (caddr_t)pa, size, PG_RW|PG_CI);
350 return((caddr_t)kva);
351 }
352