obio.c revision 1.31 1 1.31 pk /* $NetBSD: obio.c,v 1.31 1997/04/08 20:08:20 pk Exp $ */
2 1.1 deraadt
3 1.1 deraadt /*
4 1.1 deraadt * Copyright (c) 1993, 1994 Theo de Raadt
5 1.22 pk * Copyright (c) 1995 Paul Kranenburg
6 1.1 deraadt * All rights reserved.
7 1.1 deraadt *
8 1.1 deraadt * Redistribution and use in source and binary forms, with or without
9 1.1 deraadt * modification, are permitted provided that the following conditions
10 1.1 deraadt * are met:
11 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
12 1.1 deraadt * notice, this list of conditions and the following disclaimer.
13 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
15 1.1 deraadt * documentation and/or other materials provided with the distribution.
16 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
17 1.1 deraadt * must display the following acknowledgement:
18 1.1 deraadt * This product includes software developed by Theo de Raadt.
19 1.1 deraadt * 4. The name of the author may not be used to endorse or promote products
20 1.1 deraadt * derived from this software without specific prior written permission.
21 1.1 deraadt *
22 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 deraadt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 deraadt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 deraadt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 deraadt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 deraadt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 deraadt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 deraadt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 deraadt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 deraadt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 deraadt */
33 1.1 deraadt
34 1.1 deraadt #include <sys/param.h>
35 1.20 christos #include <sys/systm.h>
36 1.1 deraadt #include <sys/device.h>
37 1.1 deraadt #include <sys/malloc.h>
38 1.1 deraadt
39 1.1 deraadt #ifdef DEBUG
40 1.1 deraadt #include <sys/proc.h>
41 1.1 deraadt #include <sys/syslog.h>
42 1.1 deraadt #endif
43 1.1 deraadt
44 1.1 deraadt #include <vm/vm.h>
45 1.1 deraadt
46 1.1 deraadt #include <machine/autoconf.h>
47 1.1 deraadt #include <machine/pmap.h>
48 1.2 deraadt #include <machine/oldmon.h>
49 1.5 deraadt #include <machine/cpu.h>
50 1.2 deraadt #include <machine/ctlreg.h>
51 1.2 deraadt #include <sparc/sparc/asm.h>
52 1.2 deraadt #include <sparc/sparc/vaddrs.h>
53 1.30 pk #include <sparc/sparc/cpuvar.h>
54 1.22 pk #include <sparc/dev/sbusvar.h>
55 1.1 deraadt
56 1.4 deraadt struct bus_softc {
57 1.22 pk union {
58 1.22 pk struct device scu_dev; /* base device */
59 1.22 pk struct sbus_softc scu_sbus; /* obio is another sbus slot */
60 1.22 pk } bu;
61 1.22 pk #define sc_dev bu.scu_dev
62 1.1 deraadt };
63 1.1 deraadt
64 1.1 deraadt /* autoconfiguration driver */
65 1.28 pk static int busmatch __P((struct device *, struct cfdata *, void *));
66 1.9 deraadt static void obioattach __P((struct device *, struct device *, void *));
67 1.9 deraadt static void vmesattach __P((struct device *, struct device *, void *));
68 1.9 deraadt static void vmelattach __P((struct device *, struct device *, void *));
69 1.22 pk
70 1.25 cgd int busprint __P((void *, const char *));
71 1.28 pk static int busattach __P((struct device *, struct cfdata *, void *, int));
72 1.17 pk void * bus_map __P((struct rom_reg *, int, int));
73 1.28 pk int obio_scan __P((struct device *, struct cfdata *, void *));
74 1.28 pk int vmes_scan __P((struct device *, struct cfdata *, void *));
75 1.28 pk int vmel_scan __P((struct device *, struct cfdata *, void *));
76 1.20 christos int vmeintr __P((void *));
77 1.4 deraadt
78 1.21 thorpej struct cfattach obio_ca = {
79 1.21 thorpej sizeof(struct bus_softc), busmatch, obioattach
80 1.4 deraadt };
81 1.21 thorpej
82 1.21 thorpej struct cfdriver obio_cd = {
83 1.21 thorpej NULL, "obio", DV_DULL
84 1.21 thorpej };
85 1.21 thorpej
86 1.21 thorpej struct cfattach vmel_ca = {
87 1.21 thorpej sizeof(struct bus_softc), busmatch, vmelattach
88 1.21 thorpej };
89 1.21 thorpej
90 1.21 thorpej struct cfdriver vmel_cd = {
91 1.21 thorpej NULL, "vmel", DV_DULL
92 1.21 thorpej };
93 1.21 thorpej
94 1.21 thorpej struct cfattach vmes_ca = {
95 1.21 thorpej sizeof(struct bus_softc), busmatch, vmesattach
96 1.1 deraadt };
97 1.21 thorpej
98 1.21 thorpej struct cfdriver vmes_cd = {
99 1.21 thorpej NULL, "vmes", DV_DULL
100 1.4 deraadt };
101 1.22 pk
102 1.22 pk struct intrhand **vmeints;
103 1.4 deraadt
104 1.2 deraadt
105 1.1 deraadt int
106 1.28 pk busmatch(parent, cf, aux)
107 1.1 deraadt struct device *parent;
108 1.28 pk struct cfdata *cf;
109 1.28 pk void *aux;
110 1.1 deraadt {
111 1.3 deraadt register struct confargs *ca = aux;
112 1.3 deraadt register struct romaux *ra = &ca->ca_ra;
113 1.3 deraadt
114 1.22 pk if (CPU_ISSUN4M)
115 1.22 pk return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
116 1.22 pk
117 1.22 pk if (!CPU_ISSUN4)
118 1.3 deraadt return (0);
119 1.22 pk
120 1.3 deraadt return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
121 1.1 deraadt }
122 1.1 deraadt
123 1.1 deraadt int
124 1.4 deraadt busprint(args, obio)
125 1.1 deraadt void *args;
126 1.25 cgd const char *obio;
127 1.1 deraadt {
128 1.2 deraadt register struct confargs *ca = args;
129 1.2 deraadt
130 1.2 deraadt if (ca->ca_ra.ra_name == NULL)
131 1.2 deraadt ca->ca_ra.ra_name = "<unknown>";
132 1.22 pk
133 1.2 deraadt if (obio)
134 1.27 christos printf("[%s at %s]", ca->ca_ra.ra_name, obio);
135 1.22 pk
136 1.27 christos printf(" addr %p", ca->ca_ra.ra_paddr);
137 1.22 pk
138 1.22 pk if (CPU_ISSUN4 && ca->ca_ra.ra_intr[0].int_vec != -1)
139 1.27 christos printf(" vec 0x%x", ca->ca_ra.ra_intr[0].int_vec);
140 1.22 pk
141 1.1 deraadt return (UNCONF);
142 1.1 deraadt }
143 1.1 deraadt
144 1.14 pk
145 1.22 pk void
146 1.22 pk obioattach(parent, self, args)
147 1.22 pk struct device *parent, *self;
148 1.22 pk void *args;
149 1.22 pk {
150 1.22 pk #if defined(SUN4M)
151 1.22 pk register struct bus_softc *sc = (struct bus_softc *)self;
152 1.22 pk struct confargs oca, *ca = args;
153 1.22 pk register struct romaux *ra = &ca->ca_ra;
154 1.22 pk register int node0, node;
155 1.22 pk register char *name;
156 1.22 pk register const char *sp;
157 1.22 pk const char *const *ssp;
158 1.31 pk int rlen;
159 1.22 pk extern int autoconf_nzs;
160 1.22 pk
161 1.22 pk static const char *const special4m[] = {
162 1.22 pk /* find these first */
163 1.22 pk "eeprom",
164 1.22 pk "counter",
165 1.29 pk #if 0 /* Not all sun4m's have an `auxio' */
166 1.22 pk "auxio",
167 1.29 pk #endif
168 1.22 pk "",
169 1.22 pk /* place device to ignore here */
170 1.22 pk "interrupt",
171 1.22 pk NULL
172 1.22 pk };
173 1.22 pk #endif
174 1.22 pk
175 1.22 pk if (CPU_ISSUN4) {
176 1.22 pk if (self->dv_unit > 0) {
177 1.27 christos printf(" unsupported\n");
178 1.22 pk return;
179 1.22 pk }
180 1.27 christos printf("\n");
181 1.22 pk
182 1.22 pk (void)config_search(obio_scan, self, args);
183 1.22 pk bus_untmp();
184 1.22 pk }
185 1.22 pk
186 1.22 pk #if defined(SUN4M)
187 1.22 pk if (!CPU_ISSUN4M)
188 1.22 pk return;
189 1.22 pk
190 1.22 pk /*
191 1.22 pk * There is only one obio bus (it is in fact one of the Sbus slots)
192 1.22 pk * How about VME?
193 1.22 pk */
194 1.22 pk if (sc->sc_dev.dv_unit > 0) {
195 1.27 christos printf(" unsupported\n");
196 1.22 pk return;
197 1.22 pk }
198 1.22 pk
199 1.27 christos printf("\n");
200 1.22 pk
201 1.22 pk if (ra->ra_bp != NULL && strcmp(ra->ra_bp->name, "obio") == 0)
202 1.22 pk oca.ca_ra.ra_bp = ra->ra_bp + 1;
203 1.22 pk else
204 1.22 pk oca.ca_ra.ra_bp = NULL;
205 1.22 pk
206 1.31 pk node = ra->ra_node;
207 1.31 pk rlen = getproplen(node, "ranges");
208 1.31 pk if (rlen > 0) {
209 1.31 pk sc->bu.scu_sbus.sc_nrange = rlen / sizeof(struct rom_range);
210 1.31 pk sc->bu.scu_sbus.sc_range =
211 1.31 pk (struct rom_range *)malloc(rlen, M_DEVBUF, M_NOWAIT);
212 1.31 pk if (sc->bu.scu_sbus.sc_range == 0)
213 1.31 pk panic("obio: PROM ranges too large: %d", rlen);
214 1.31 pk (void)getprop(node, "ranges", sc->bu.scu_sbus.sc_range, rlen);
215 1.31 pk }
216 1.22 pk
217 1.22 pk /*
218 1.22 pk * Loop through ROM children, fixing any relative addresses
219 1.22 pk * and then configuring each device.
220 1.22 pk * We first do the crucial ones, such as eeprom, etc.
221 1.22 pk */
222 1.22 pk node0 = firstchild(ra->ra_node);
223 1.22 pk for (ssp = special4m ; *(sp = *ssp) != 0; ssp++) {
224 1.22 pk if ((node = findnode(node0, sp)) == 0) {
225 1.27 christos printf("could not find %s amongst obio devices\n", sp);
226 1.22 pk panic(sp);
227 1.22 pk }
228 1.22 pk if (!romprop(&oca.ca_ra, sp, node))
229 1.22 pk continue;
230 1.22 pk
231 1.22 pk sbus_translate(self, &oca);
232 1.22 pk oca.ca_bustype = BUS_OBIO;
233 1.22 pk (void) config_found(&sc->sc_dev, (void *)&oca, busprint);
234 1.22 pk }
235 1.22 pk
236 1.22 pk for (node = node0; node; node = nextsibling(node)) {
237 1.22 pk name = getpropstring(node, "name");
238 1.22 pk for (ssp = special4m ; (sp = *ssp) != NULL; ssp++)
239 1.22 pk if (strcmp(name, sp) == 0)
240 1.22 pk break;
241 1.22 pk
242 1.22 pk if (sp != NULL || !romprop(&oca.ca_ra, name, node))
243 1.22 pk continue;
244 1.22 pk
245 1.22 pk if (strcmp(name, "zs") == 0)
246 1.22 pk /* XXX - see autoconf.c for this hack */
247 1.22 pk autoconf_nzs++;
248 1.22 pk
249 1.22 pk /* Translate into parent address spaces */
250 1.22 pk sbus_translate(self, &oca);
251 1.22 pk oca.ca_bustype = BUS_OBIO;
252 1.22 pk (void) config_found(&sc->sc_dev, (void *)&oca, busprint);
253 1.22 pk }
254 1.22 pk #endif
255 1.22 pk }
256 1.22 pk
257 1.22 pk void
258 1.22 pk vmesattach(parent, self, args)
259 1.22 pk struct device *parent, *self;
260 1.22 pk void *args;
261 1.22 pk {
262 1.22 pk if (CPU_ISSUN4M || self->dv_unit > 0) {
263 1.27 christos printf(" unsupported\n");
264 1.22 pk return;
265 1.22 pk }
266 1.27 christos printf("\n");
267 1.22 pk
268 1.22 pk if (vmeints == NULL) {
269 1.22 pk vmeints = (struct intrhand **)malloc(256 *
270 1.22 pk sizeof(struct intrhand *), M_TEMP, M_NOWAIT);
271 1.22 pk bzero(vmeints, 256 * sizeof(struct intrhand *));
272 1.22 pk }
273 1.22 pk (void)config_search(vmes_scan, self, args);
274 1.22 pk bus_untmp();
275 1.22 pk }
276 1.22 pk
277 1.22 pk void
278 1.22 pk vmelattach(parent, self, args)
279 1.22 pk struct device *parent, *self;
280 1.22 pk void *args;
281 1.22 pk {
282 1.22 pk if (CPU_ISSUN4M || self->dv_unit > 0) {
283 1.27 christos printf(" unsupported\n");
284 1.22 pk return;
285 1.22 pk }
286 1.27 christos printf("\n");
287 1.22 pk
288 1.22 pk if (vmeints == NULL) {
289 1.22 pk vmeints = (struct intrhand **)malloc(256 *
290 1.22 pk sizeof(struct intrhand *), M_TEMP, M_NOWAIT);
291 1.22 pk bzero(vmeints, 256 * sizeof(struct intrhand *));
292 1.22 pk }
293 1.22 pk (void)config_search(vmel_scan, self, args);
294 1.22 pk bus_untmp();
295 1.22 pk }
296 1.22 pk
297 1.14 pk int
298 1.28 pk busattach(parent, cf, args, bustype)
299 1.14 pk struct device *parent;
300 1.28 pk struct cfdata *cf;
301 1.28 pk void *args;
302 1.4 deraadt int bustype;
303 1.1 deraadt {
304 1.22 pk #if defined(SUN4)
305 1.3 deraadt register struct confargs *ca = args;
306 1.3 deraadt struct confargs oca;
307 1.4 deraadt caddr_t tmp;
308 1.1 deraadt
309 1.22 pk if (bustype == BUS_OBIO && CPU_ISSUN4) {
310 1.23 chuck
311 1.23 chuck /*
312 1.23 chuck * avoid sun4m entries which don't have valid PA's.
313 1.23 chuck * no point in even probing them.
314 1.23 chuck */
315 1.23 chuck if (cf->cf_loc[0] == -1) return 0;
316 1.23 chuck
317 1.14 pk /*
318 1.14 pk * On the 4/100 obio addresses must be mapped at
319 1.14 pk * 0x0YYYYYYY, but alias higher up (we avoid the
320 1.14 pk * alias condition because it causes pmap difficulties)
321 1.14 pk * XXX: We also assume that 4/[23]00 obio addresses
322 1.14 pk * must be 0xZYYYYYYY, where (Z != 0)
323 1.14 pk */
324 1.30 pk if (cpuinfo.cpu_type == CPUTYP_4_100 &&
325 1.30 pk (cf->cf_loc[0] & 0xf0000000))
326 1.14 pk return 0;
327 1.30 pk if (cpuinfo.cpu_type != CPUTYP_4_100 &&
328 1.30 pk !(cf->cf_loc[0] & 0xf0000000))
329 1.14 pk return 0;
330 1.14 pk }
331 1.14 pk
332 1.14 pk oca.ca_ra.ra_iospace = -1;
333 1.14 pk oca.ca_ra.ra_paddr = (void *)cf->cf_loc[0];
334 1.14 pk oca.ca_ra.ra_len = 0;
335 1.14 pk oca.ca_ra.ra_nreg = 1;
336 1.14 pk if (oca.ca_ra.ra_paddr)
337 1.24 mrg tmp = (caddr_t)bus_tmp(oca.ca_ra.ra_paddr,
338 1.14 pk bustype);
339 1.24 mrg else
340 1.24 mrg tmp = NULL;
341 1.14 pk oca.ca_ra.ra_vaddr = tmp;
342 1.14 pk oca.ca_ra.ra_intr[0].int_pri = cf->cf_loc[1];
343 1.14 pk if (bustype == BUS_VME16 || bustype == BUS_VME32)
344 1.14 pk oca.ca_ra.ra_intr[0].int_vec = cf->cf_loc[2];
345 1.14 pk else
346 1.14 pk oca.ca_ra.ra_intr[0].int_vec = -1;
347 1.14 pk oca.ca_ra.ra_nintr = 1;
348 1.14 pk oca.ca_ra.ra_name = cf->cf_driver->cd_name;
349 1.15 pk if (ca->ca_ra.ra_bp != NULL &&
350 1.16 pk ((bustype == BUS_VME16 && strcmp(ca->ca_ra.ra_bp->name,"vmes") ==0) ||
351 1.16 pk (bustype == BUS_VME32 && strcmp(ca->ca_ra.ra_bp->name,"vmel") ==0) ||
352 1.16 pk (bustype == BUS_OBIO && strcmp(ca->ca_ra.ra_bp->name,"obio") == 0)))
353 1.15 pk oca.ca_ra.ra_bp = ca->ca_ra.ra_bp + 1;
354 1.15 pk else
355 1.15 pk oca.ca_ra.ra_bp = NULL;
356 1.14 pk oca.ca_bustype = bustype;
357 1.14 pk
358 1.21 thorpej if ((*cf->cf_attach->ca_match)(parent, cf, &oca) == 0)
359 1.14 pk return 0;
360 1.14 pk
361 1.14 pk /*
362 1.22 pk * check if XXmatch routine replaced the temporary mapping with
363 1.19 chuck * a real mapping. If not, then make sure we don't pass the
364 1.19 chuck * tmp mapping to the attach routine.
365 1.14 pk */
366 1.19 chuck if (oca.ca_ra.ra_vaddr == tmp)
367 1.19 chuck oca.ca_ra.ra_vaddr = NULL; /* wipe out tmp address */
368 1.14 pk /*
369 1.22 pk * the match routine will set "ra_len" if it wants us to
370 1.19 chuck * establish a mapping for it.
371 1.14 pk * (which won't be seen on future XXmatch calls,
372 1.14 pk * so not as useful as it seems.)
373 1.14 pk */
374 1.22 pk if (oca.ca_ra.ra_len)
375 1.14 pk oca.ca_ra.ra_vaddr =
376 1.17 pk bus_map(oca.ca_ra.ra_reg,
377 1.14 pk oca.ca_ra.ra_len, oca.ca_bustype);
378 1.14 pk
379 1.14 pk config_attach(parent, cf, &oca, busprint);
380 1.14 pk return 1;
381 1.22 pk #else
382 1.22 pk return 0;
383 1.22 pk #endif
384 1.14 pk }
385 1.4 deraadt
386 1.14 pk int
387 1.14 pk obio_scan(parent, child, args)
388 1.14 pk struct device *parent;
389 1.28 pk struct cfdata *child;
390 1.28 pk void *args;
391 1.14 pk {
392 1.14 pk return busattach(parent, child, args, BUS_OBIO);
393 1.4 deraadt }
394 1.5 deraadt
395 1.14 pk int
396 1.14 pk vmes_scan(parent, child, args)
397 1.14 pk struct device *parent;
398 1.28 pk struct cfdata *child;
399 1.28 pk void *args;
400 1.14 pk {
401 1.14 pk return busattach(parent, child, args, BUS_VME16);
402 1.14 pk }
403 1.14 pk
404 1.14 pk int
405 1.14 pk vmel_scan(parent, child, args)
406 1.14 pk struct device *parent;
407 1.28 pk struct cfdata *child;
408 1.28 pk void *args;
409 1.14 pk {
410 1.14 pk return busattach(parent, child, args, BUS_VME32);
411 1.4 deraadt }
412 1.4 deraadt
413 1.5 deraadt int pil_to_vme[] = {
414 1.5 deraadt -1, /* pil 0 */
415 1.5 deraadt -1, /* pil 1 */
416 1.5 deraadt 1, /* pil 2 */
417 1.5 deraadt 2, /* pil 3 */
418 1.5 deraadt -1, /* pil 4 */
419 1.5 deraadt 3, /* pil 5 */
420 1.5 deraadt -1, /* pil 6 */
421 1.5 deraadt 4, /* pil 7 */
422 1.5 deraadt -1, /* pil 8 */
423 1.5 deraadt 5, /* pil 9 */
424 1.5 deraadt -1, /* pil 10 */
425 1.5 deraadt 6, /* pil 11 */
426 1.5 deraadt -1, /* pil 12 */
427 1.5 deraadt 7, /* pil 13 */
428 1.5 deraadt -1, /* pil 14 */
429 1.5 deraadt -1, /* pil 15 */
430 1.5 deraadt };
431 1.5 deraadt
432 1.5 deraadt int
433 1.5 deraadt vmeintr(arg)
434 1.5 deraadt void *arg;
435 1.5 deraadt {
436 1.5 deraadt int level = (int)arg, vec;
437 1.5 deraadt struct intrhand *ih;
438 1.5 deraadt int i = 0;
439 1.5 deraadt
440 1.22 pk #ifdef DIAGNOSTIC
441 1.22 pk if (!CPU_ISSUN4) {
442 1.22 pk panic("vme: spurious interrupt");
443 1.22 pk }
444 1.22 pk #endif
445 1.22 pk
446 1.20 christos vec = ldcontrolb((caddr_t)
447 1.20 christos (AC_VMEINTVEC | (pil_to_vme[level] << 1) | 1));
448 1.6 deraadt if (vec == -1) {
449 1.27 christos printf("vme: spurious interrupt\n");
450 1.6 deraadt return 0;
451 1.6 deraadt }
452 1.5 deraadt
453 1.5 deraadt for (ih = vmeints[vec]; ih; ih = ih->ih_next)
454 1.5 deraadt if (ih->ih_fun)
455 1.5 deraadt i += (ih->ih_fun)(ih->ih_arg);
456 1.5 deraadt return (i);
457 1.5 deraadt }
458 1.5 deraadt
459 1.5 deraadt void
460 1.5 deraadt vmeintr_establish(vec, level, ih)
461 1.5 deraadt int vec, level;
462 1.5 deraadt struct intrhand *ih;
463 1.22 pk {
464 1.5 deraadt struct intrhand *ihs;
465 1.5 deraadt
466 1.22 pk if (!CPU_ISSUN4) {
467 1.22 pk panic("vmeintr_establish: not supported on cpu-type %d",
468 1.22 pk cputyp);
469 1.22 pk }
470 1.22 pk
471 1.8 deraadt if (vec == -1)
472 1.8 deraadt panic("vmeintr_establish: uninitialized vec\n");
473 1.8 deraadt
474 1.5 deraadt if (vmeints[vec] == NULL)
475 1.5 deraadt vmeints[vec] = ih;
476 1.5 deraadt else {
477 1.5 deraadt for (ihs = vmeints[vec]; ihs->ih_next; ihs = ihs->ih_next)
478 1.5 deraadt ;
479 1.5 deraadt ihs->ih_next = ih;
480 1.5 deraadt }
481 1.5 deraadt
482 1.5 deraadt /* ensure the interrupt subsystem will call us at this level */
483 1.5 deraadt for (ihs = intrhand[level]; ihs; ihs = ihs->ih_next)
484 1.5 deraadt if (ihs->ih_fun == vmeintr)
485 1.5 deraadt return;
486 1.5 deraadt
487 1.5 deraadt ihs = (struct intrhand *)malloc(sizeof(struct intrhand),
488 1.5 deraadt M_TEMP, M_NOWAIT);
489 1.5 deraadt if (ihs == NULL)
490 1.5 deraadt panic("vme_addirq");
491 1.5 deraadt bzero(ihs, sizeof *ihs);
492 1.5 deraadt ihs->ih_fun = vmeintr;
493 1.5 deraadt ihs->ih_arg = (void *)level;
494 1.5 deraadt intr_establish(level, ihs);
495 1.5 deraadt }
496 1.4 deraadt
497 1.2 deraadt #define getpte(va) lda(va, ASI_PTE)
498 1.2 deraadt
499 1.2 deraadt /*
500 1.2 deraadt * If we can find a mapping that was established by the rom, use it.
501 1.2 deraadt * Else, create a new mapping.
502 1.2 deraadt */
503 1.2 deraadt void *
504 1.4 deraadt bus_map(pa, len, bustype)
505 1.17 pk struct rom_reg *pa;
506 1.2 deraadt int len;
507 1.4 deraadt int bustype;
508 1.2 deraadt {
509 1.18 pk u_long pf = (u_long)(pa->rr_paddr) >> PGSHIFT;
510 1.2 deraadt u_long va, pte;
511 1.20 christos int pgtype = -1;
512 1.4 deraadt
513 1.4 deraadt switch (bt2pmt[bustype]) {
514 1.4 deraadt case PMAP_OBIO:
515 1.4 deraadt pgtype = PG_OBIO;
516 1.4 deraadt break;
517 1.4 deraadt case PMAP_VME32:
518 1.4 deraadt pgtype = PG_VME32;
519 1.4 deraadt break;
520 1.4 deraadt case PMAP_VME16:
521 1.4 deraadt pgtype = PG_VME16;
522 1.4 deraadt break;
523 1.4 deraadt }
524 1.2 deraadt
525 1.3 deraadt if (len <= NBPG) {
526 1.3 deraadt for (va = OLDMON_STARTVADDR; va < OLDMON_ENDVADDR; va += NBPG) {
527 1.3 deraadt pte = getpte(va);
528 1.4 deraadt if ((pte & PG_V) != 0 && (pte & PG_TYPE) == pgtype &&
529 1.3 deraadt (pte & PG_PFNUM) == pf)
530 1.19 chuck return ((void *)
531 1.19 chuck (va | ((u_long)pa->rr_paddr & PGOFSET)) );
532 1.19 chuck /* note: preserve page offset */
533 1.3 deraadt }
534 1.2 deraadt }
535 1.17 pk return mapiodev(pa, 0, len, bustype);
536 1.2 deraadt }
537 1.2 deraadt
538 1.2 deraadt void *
539 1.4 deraadt bus_tmp(pa, bustype)
540 1.2 deraadt void *pa;
541 1.4 deraadt int bustype;
542 1.2 deraadt {
543 1.3 deraadt vm_offset_t addr = (vm_offset_t)pa & ~PGOFSET;
544 1.4 deraadt int pmtype = bt2pmt[bustype];
545 1.3 deraadt
546 1.13 mycroft pmap_enter(pmap_kernel(), TMPMAP_VA,
547 1.22 pk addr | pmtype | PMAP_NC,
548 1.22 pk VM_PROT_READ | VM_PROT_WRITE, 1);
549 1.19 chuck return ((void *)(TMPMAP_VA | ((u_long) pa & PGOFSET)) );
550 1.2 deraadt }
551 1.2 deraadt
552 1.2 deraadt void
553 1.4 deraadt bus_untmp()
554 1.2 deraadt {
555 1.13 mycroft pmap_remove(pmap_kernel(), TMPMAP_VA, TMPMAP_VA+NBPG);
556 1.1 deraadt }
557