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