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