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