obio.c revision 1.23 1 1.23 chuck /* $NetBSD: obio.c,v 1.23 1996/04/05 21:50:05 chuck 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.22 pk #include <sparc/dev/sbusvar.h>
54 1.1 deraadt
55 1.4 deraadt struct bus_softc {
56 1.22 pk union {
57 1.22 pk struct device scu_dev; /* base device */
58 1.22 pk struct sbus_softc scu_sbus; /* obio is another sbus slot */
59 1.22 pk } bu;
60 1.22 pk #define sc_dev bu.scu_dev
61 1.1 deraadt };
62 1.1 deraadt
63 1.1 deraadt /* autoconfiguration driver */
64 1.9 deraadt static int busmatch __P((struct device *, void *, void *));
65 1.9 deraadt static void obioattach __P((struct device *, struct device *, void *));
66 1.9 deraadt static void vmesattach __P((struct device *, struct device *, void *));
67 1.9 deraadt static void vmelattach __P((struct device *, struct device *, void *));
68 1.22 pk
69 1.22 pk int busprint __P((void *, char *));
70 1.17 pk static int busattach __P((struct device *, void *, void *, int));
71 1.17 pk void * bus_map __P((struct rom_reg *, int, int));
72 1.20 christos int obio_scan __P((struct device *, void *, void *));
73 1.20 christos int vmes_scan __P((struct device *, void *, void *));
74 1.20 christos int vmel_scan __P((struct device *, void *, void *));
75 1.20 christos int vmeintr __P((void *));
76 1.4 deraadt
77 1.21 thorpej struct cfattach obio_ca = {
78 1.21 thorpej sizeof(struct bus_softc), busmatch, obioattach
79 1.4 deraadt };
80 1.21 thorpej
81 1.21 thorpej struct cfdriver obio_cd = {
82 1.21 thorpej NULL, "obio", DV_DULL
83 1.21 thorpej };
84 1.21 thorpej
85 1.21 thorpej struct cfattach vmel_ca = {
86 1.21 thorpej sizeof(struct bus_softc), busmatch, vmelattach
87 1.21 thorpej };
88 1.21 thorpej
89 1.21 thorpej struct cfdriver vmel_cd = {
90 1.21 thorpej NULL, "vmel", DV_DULL
91 1.21 thorpej };
92 1.21 thorpej
93 1.21 thorpej struct cfattach vmes_ca = {
94 1.21 thorpej sizeof(struct bus_softc), busmatch, vmesattach
95 1.1 deraadt };
96 1.21 thorpej
97 1.21 thorpej struct cfdriver vmes_cd = {
98 1.21 thorpej NULL, "vmes", DV_DULL
99 1.4 deraadt };
100 1.22 pk
101 1.22 pk struct intrhand **vmeints;
102 1.4 deraadt
103 1.2 deraadt
104 1.1 deraadt int
105 1.9 deraadt busmatch(parent, vcf, aux)
106 1.1 deraadt struct device *parent;
107 1.9 deraadt void *vcf, *aux;
108 1.1 deraadt {
109 1.9 deraadt struct cfdata *cf = vcf;
110 1.3 deraadt register struct confargs *ca = aux;
111 1.3 deraadt register struct romaux *ra = &ca->ca_ra;
112 1.3 deraadt
113 1.22 pk if (CPU_ISSUN4M)
114 1.22 pk return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
115 1.22 pk
116 1.22 pk if (!CPU_ISSUN4)
117 1.3 deraadt return (0);
118 1.22 pk
119 1.3 deraadt return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
120 1.1 deraadt }
121 1.1 deraadt
122 1.1 deraadt int
123 1.4 deraadt busprint(args, obio)
124 1.1 deraadt void *args;
125 1.1 deraadt char *obio;
126 1.1 deraadt {
127 1.2 deraadt register struct confargs *ca = args;
128 1.2 deraadt
129 1.2 deraadt if (ca->ca_ra.ra_name == NULL)
130 1.2 deraadt ca->ca_ra.ra_name = "<unknown>";
131 1.22 pk
132 1.2 deraadt if (obio)
133 1.3 deraadt printf("[%s at %s]", ca->ca_ra.ra_name, obio);
134 1.22 pk
135 1.20 christos printf(" addr %p", ca->ca_ra.ra_paddr);
136 1.22 pk
137 1.22 pk if (CPU_ISSUN4 && ca->ca_ra.ra_intr[0].int_vec != -1)
138 1.7 deraadt printf(" vec 0x%x", ca->ca_ra.ra_intr[0].int_vec);
139 1.22 pk
140 1.1 deraadt return (UNCONF);
141 1.1 deraadt }
142 1.1 deraadt
143 1.14 pk
144 1.22 pk void
145 1.22 pk obioattach(parent, self, args)
146 1.22 pk struct device *parent, *self;
147 1.22 pk void *args;
148 1.22 pk {
149 1.22 pk #if defined(SUN4M)
150 1.22 pk register struct bus_softc *sc = (struct bus_softc *)self;
151 1.22 pk struct confargs oca, *ca = args;
152 1.22 pk register struct romaux *ra = &ca->ca_ra;
153 1.22 pk register int node0, node;
154 1.22 pk register char *name;
155 1.22 pk register const char *sp;
156 1.22 pk const char *const *ssp;
157 1.22 pk extern int autoconf_nzs;
158 1.22 pk
159 1.22 pk static const char *const special4m[] = {
160 1.22 pk /* find these first */
161 1.22 pk "eeprom",
162 1.22 pk "counter",
163 1.22 pk "auxio",
164 1.22 pk "",
165 1.22 pk /* place device to ignore here */
166 1.22 pk "interrupt",
167 1.22 pk NULL
168 1.22 pk };
169 1.22 pk #endif
170 1.22 pk
171 1.22 pk if (CPU_ISSUN4) {
172 1.22 pk if (self->dv_unit > 0) {
173 1.22 pk printf(" unsupported\n");
174 1.22 pk return;
175 1.22 pk }
176 1.22 pk printf("\n");
177 1.22 pk
178 1.22 pk (void)config_search(obio_scan, self, args);
179 1.22 pk bus_untmp();
180 1.22 pk }
181 1.22 pk
182 1.22 pk #if defined(SUN4M)
183 1.22 pk if (!CPU_ISSUN4M)
184 1.22 pk return;
185 1.22 pk
186 1.22 pk /*
187 1.22 pk * There is only one obio bus (it is in fact one of the Sbus slots)
188 1.22 pk * How about VME?
189 1.22 pk */
190 1.22 pk if (sc->sc_dev.dv_unit > 0) {
191 1.22 pk printf(" unsupported\n");
192 1.22 pk return;
193 1.22 pk }
194 1.22 pk
195 1.22 pk printf("\n");
196 1.22 pk
197 1.22 pk if (ra->ra_bp != NULL && strcmp(ra->ra_bp->name, "obio") == 0)
198 1.22 pk oca.ca_ra.ra_bp = ra->ra_bp + 1;
199 1.22 pk else
200 1.22 pk oca.ca_ra.ra_bp = NULL;
201 1.22 pk
202 1.22 pk sc->bu.scu_sbus.sc_range = ra->ra_range;
203 1.22 pk sc->bu.scu_sbus.sc_nrange = ra->ra_nrange;
204 1.22 pk
205 1.22 pk /*
206 1.22 pk * Loop through ROM children, fixing any relative addresses
207 1.22 pk * and then configuring each device.
208 1.22 pk * We first do the crucial ones, such as eeprom, etc.
209 1.22 pk */
210 1.22 pk node0 = firstchild(ra->ra_node);
211 1.22 pk for (ssp = special4m ; *(sp = *ssp) != 0; ssp++) {
212 1.22 pk if ((node = findnode(node0, sp)) == 0) {
213 1.22 pk printf("could not find %s amongst obio devices\n", sp);
214 1.22 pk panic(sp);
215 1.22 pk }
216 1.22 pk if (!romprop(&oca.ca_ra, sp, node))
217 1.22 pk continue;
218 1.22 pk
219 1.22 pk sbus_translate(self, &oca);
220 1.22 pk oca.ca_bustype = BUS_OBIO;
221 1.22 pk (void) config_found(&sc->sc_dev, (void *)&oca, busprint);
222 1.22 pk }
223 1.22 pk
224 1.22 pk for (node = node0; node; node = nextsibling(node)) {
225 1.22 pk name = getpropstring(node, "name");
226 1.22 pk for (ssp = special4m ; (sp = *ssp) != NULL; ssp++)
227 1.22 pk if (strcmp(name, sp) == 0)
228 1.22 pk break;
229 1.22 pk
230 1.22 pk if (sp != NULL || !romprop(&oca.ca_ra, name, node))
231 1.22 pk continue;
232 1.22 pk
233 1.22 pk if (strcmp(name, "zs") == 0)
234 1.22 pk /* XXX - see autoconf.c for this hack */
235 1.22 pk autoconf_nzs++;
236 1.22 pk
237 1.22 pk /* Translate into parent address spaces */
238 1.22 pk sbus_translate(self, &oca);
239 1.22 pk oca.ca_bustype = BUS_OBIO;
240 1.22 pk (void) config_found(&sc->sc_dev, (void *)&oca, busprint);
241 1.22 pk }
242 1.22 pk #endif
243 1.22 pk }
244 1.22 pk
245 1.22 pk void
246 1.22 pk vmesattach(parent, self, args)
247 1.22 pk struct device *parent, *self;
248 1.22 pk void *args;
249 1.22 pk {
250 1.22 pk if (CPU_ISSUN4M || self->dv_unit > 0) {
251 1.22 pk printf(" unsupported\n");
252 1.22 pk return;
253 1.22 pk }
254 1.22 pk printf("\n");
255 1.22 pk
256 1.22 pk if (vmeints == NULL) {
257 1.22 pk vmeints = (struct intrhand **)malloc(256 *
258 1.22 pk sizeof(struct intrhand *), M_TEMP, M_NOWAIT);
259 1.22 pk bzero(vmeints, 256 * sizeof(struct intrhand *));
260 1.22 pk }
261 1.22 pk (void)config_search(vmes_scan, self, args);
262 1.22 pk bus_untmp();
263 1.22 pk }
264 1.22 pk
265 1.22 pk void
266 1.22 pk vmelattach(parent, self, args)
267 1.22 pk struct device *parent, *self;
268 1.22 pk void *args;
269 1.22 pk {
270 1.22 pk if (CPU_ISSUN4M || self->dv_unit > 0) {
271 1.22 pk printf(" unsupported\n");
272 1.22 pk return;
273 1.22 pk }
274 1.22 pk printf("\n");
275 1.22 pk
276 1.22 pk if (vmeints == NULL) {
277 1.22 pk vmeints = (struct intrhand **)malloc(256 *
278 1.22 pk sizeof(struct intrhand *), M_TEMP, M_NOWAIT);
279 1.22 pk bzero(vmeints, 256 * sizeof(struct intrhand *));
280 1.22 pk }
281 1.22 pk (void)config_search(vmel_scan, self, args);
282 1.22 pk bus_untmp();
283 1.22 pk }
284 1.22 pk
285 1.14 pk int
286 1.14 pk busattach(parent, child, args, bustype)
287 1.14 pk struct device *parent;
288 1.14 pk void *args, *child;
289 1.4 deraadt int bustype;
290 1.1 deraadt {
291 1.22 pk #if defined(SUN4)
292 1.14 pk struct cfdata *cf = child;
293 1.3 deraadt register struct confargs *ca = args;
294 1.3 deraadt struct confargs oca;
295 1.4 deraadt caddr_t tmp;
296 1.1 deraadt
297 1.22 pk if (bustype == BUS_OBIO && CPU_ISSUN4) {
298 1.23 chuck
299 1.23 chuck /*
300 1.23 chuck * avoid sun4m entries which don't have valid PA's.
301 1.23 chuck * no point in even probing them.
302 1.23 chuck */
303 1.23 chuck if (cf->cf_loc[0] == -1) return 0;
304 1.23 chuck
305 1.14 pk /*
306 1.14 pk * On the 4/100 obio addresses must be mapped at
307 1.14 pk * 0x0YYYYYYY, but alias higher up (we avoid the
308 1.14 pk * alias condition because it causes pmap difficulties)
309 1.14 pk * XXX: We also assume that 4/[23]00 obio addresses
310 1.14 pk * must be 0xZYYYYYYY, where (Z != 0)
311 1.14 pk */
312 1.22 pk if (cpumod == SUN4_100 && (cf->cf_loc[0] & 0xf0000000))
313 1.14 pk return 0;
314 1.22 pk if (cpumod != SUN4_100 && !(cf->cf_loc[0] & 0xf0000000))
315 1.14 pk return 0;
316 1.14 pk }
317 1.14 pk
318 1.14 pk if (parent->dv_cfdata->cf_driver->cd_indirect) {
319 1.14 pk printf(" indirect devices not supported\n");
320 1.14 pk return 0;
321 1.1 deraadt }
322 1.1 deraadt
323 1.14 pk oca.ca_ra.ra_iospace = -1;
324 1.14 pk oca.ca_ra.ra_paddr = (void *)cf->cf_loc[0];
325 1.14 pk oca.ca_ra.ra_len = 0;
326 1.14 pk oca.ca_ra.ra_nreg = 1;
327 1.14 pk tmp = NULL;
328 1.14 pk if (oca.ca_ra.ra_paddr)
329 1.14 pk tmp = bus_tmp(oca.ca_ra.ra_paddr,
330 1.14 pk bustype);
331 1.14 pk oca.ca_ra.ra_vaddr = tmp;
332 1.14 pk oca.ca_ra.ra_intr[0].int_pri = cf->cf_loc[1];
333 1.14 pk if (bustype == BUS_VME16 || bustype == BUS_VME32)
334 1.14 pk oca.ca_ra.ra_intr[0].int_vec = cf->cf_loc[2];
335 1.14 pk else
336 1.14 pk oca.ca_ra.ra_intr[0].int_vec = -1;
337 1.14 pk oca.ca_ra.ra_nintr = 1;
338 1.14 pk oca.ca_ra.ra_name = cf->cf_driver->cd_name;
339 1.15 pk if (ca->ca_ra.ra_bp != NULL &&
340 1.16 pk ((bustype == BUS_VME16 && strcmp(ca->ca_ra.ra_bp->name,"vmes") ==0) ||
341 1.16 pk (bustype == BUS_VME32 && strcmp(ca->ca_ra.ra_bp->name,"vmel") ==0) ||
342 1.16 pk (bustype == BUS_OBIO && strcmp(ca->ca_ra.ra_bp->name,"obio") == 0)))
343 1.15 pk oca.ca_ra.ra_bp = ca->ca_ra.ra_bp + 1;
344 1.15 pk else
345 1.15 pk oca.ca_ra.ra_bp = NULL;
346 1.14 pk oca.ca_bustype = bustype;
347 1.14 pk
348 1.21 thorpej if ((*cf->cf_attach->ca_match)(parent, cf, &oca) == 0)
349 1.14 pk return 0;
350 1.14 pk
351 1.14 pk /*
352 1.22 pk * check if XXmatch routine replaced the temporary mapping with
353 1.19 chuck * a real mapping. If not, then make sure we don't pass the
354 1.19 chuck * tmp mapping to the attach routine.
355 1.14 pk */
356 1.19 chuck if (oca.ca_ra.ra_vaddr == tmp)
357 1.19 chuck oca.ca_ra.ra_vaddr = NULL; /* wipe out tmp address */
358 1.14 pk /*
359 1.22 pk * the match routine will set "ra_len" if it wants us to
360 1.19 chuck * establish a mapping for it.
361 1.14 pk * (which won't be seen on future XXmatch calls,
362 1.14 pk * so not as useful as it seems.)
363 1.14 pk */
364 1.22 pk if (oca.ca_ra.ra_len)
365 1.14 pk oca.ca_ra.ra_vaddr =
366 1.17 pk bus_map(oca.ca_ra.ra_reg,
367 1.14 pk oca.ca_ra.ra_len, oca.ca_bustype);
368 1.14 pk
369 1.14 pk config_attach(parent, cf, &oca, busprint);
370 1.14 pk return 1;
371 1.22 pk #else
372 1.22 pk return 0;
373 1.22 pk #endif
374 1.14 pk }
375 1.4 deraadt
376 1.14 pk int
377 1.14 pk obio_scan(parent, child, args)
378 1.14 pk struct device *parent;
379 1.14 pk void *child, *args;
380 1.14 pk {
381 1.14 pk return busattach(parent, child, args, BUS_OBIO);
382 1.4 deraadt }
383 1.5 deraadt
384 1.14 pk int
385 1.14 pk vmes_scan(parent, child, args)
386 1.14 pk struct device *parent;
387 1.14 pk void *child, *args;
388 1.14 pk {
389 1.14 pk return busattach(parent, child, args, BUS_VME16);
390 1.14 pk }
391 1.14 pk
392 1.14 pk int
393 1.14 pk vmel_scan(parent, child, args)
394 1.14 pk struct device *parent;
395 1.14 pk void *child, *args;
396 1.14 pk {
397 1.14 pk return busattach(parent, child, args, BUS_VME32);
398 1.4 deraadt }
399 1.4 deraadt
400 1.5 deraadt int pil_to_vme[] = {
401 1.5 deraadt -1, /* pil 0 */
402 1.5 deraadt -1, /* pil 1 */
403 1.5 deraadt 1, /* pil 2 */
404 1.5 deraadt 2, /* pil 3 */
405 1.5 deraadt -1, /* pil 4 */
406 1.5 deraadt 3, /* pil 5 */
407 1.5 deraadt -1, /* pil 6 */
408 1.5 deraadt 4, /* pil 7 */
409 1.5 deraadt -1, /* pil 8 */
410 1.5 deraadt 5, /* pil 9 */
411 1.5 deraadt -1, /* pil 10 */
412 1.5 deraadt 6, /* pil 11 */
413 1.5 deraadt -1, /* pil 12 */
414 1.5 deraadt 7, /* pil 13 */
415 1.5 deraadt -1, /* pil 14 */
416 1.5 deraadt -1, /* pil 15 */
417 1.5 deraadt };
418 1.5 deraadt
419 1.5 deraadt int
420 1.5 deraadt vmeintr(arg)
421 1.5 deraadt void *arg;
422 1.5 deraadt {
423 1.5 deraadt int level = (int)arg, vec;
424 1.5 deraadt struct intrhand *ih;
425 1.5 deraadt int i = 0;
426 1.5 deraadt
427 1.22 pk #ifdef DIAGNOSTIC
428 1.22 pk if (!CPU_ISSUN4) {
429 1.22 pk panic("vme: spurious interrupt");
430 1.22 pk }
431 1.22 pk #endif
432 1.22 pk
433 1.20 christos vec = ldcontrolb((caddr_t)
434 1.20 christos (AC_VMEINTVEC | (pil_to_vme[level] << 1) | 1));
435 1.6 deraadt if (vec == -1) {
436 1.6 deraadt printf("vme: spurious interrupt\n");
437 1.6 deraadt return 0;
438 1.6 deraadt }
439 1.5 deraadt
440 1.5 deraadt for (ih = vmeints[vec]; ih; ih = ih->ih_next)
441 1.5 deraadt if (ih->ih_fun)
442 1.5 deraadt i += (ih->ih_fun)(ih->ih_arg);
443 1.5 deraadt return (i);
444 1.5 deraadt }
445 1.5 deraadt
446 1.5 deraadt void
447 1.5 deraadt vmeintr_establish(vec, level, ih)
448 1.5 deraadt int vec, level;
449 1.5 deraadt struct intrhand *ih;
450 1.22 pk {
451 1.5 deraadt struct intrhand *ihs;
452 1.5 deraadt
453 1.22 pk if (!CPU_ISSUN4) {
454 1.22 pk panic("vmeintr_establish: not supported on cpu-type %d",
455 1.22 pk cputyp);
456 1.22 pk }
457 1.22 pk
458 1.8 deraadt if (vec == -1)
459 1.8 deraadt panic("vmeintr_establish: uninitialized vec\n");
460 1.8 deraadt
461 1.5 deraadt if (vmeints[vec] == NULL)
462 1.5 deraadt vmeints[vec] = ih;
463 1.5 deraadt else {
464 1.5 deraadt for (ihs = vmeints[vec]; ihs->ih_next; ihs = ihs->ih_next)
465 1.5 deraadt ;
466 1.5 deraadt ihs->ih_next = ih;
467 1.5 deraadt }
468 1.5 deraadt
469 1.5 deraadt /* ensure the interrupt subsystem will call us at this level */
470 1.5 deraadt for (ihs = intrhand[level]; ihs; ihs = ihs->ih_next)
471 1.5 deraadt if (ihs->ih_fun == vmeintr)
472 1.5 deraadt return;
473 1.5 deraadt
474 1.5 deraadt ihs = (struct intrhand *)malloc(sizeof(struct intrhand),
475 1.5 deraadt M_TEMP, M_NOWAIT);
476 1.5 deraadt if (ihs == NULL)
477 1.5 deraadt panic("vme_addirq");
478 1.5 deraadt bzero(ihs, sizeof *ihs);
479 1.5 deraadt ihs->ih_fun = vmeintr;
480 1.5 deraadt ihs->ih_arg = (void *)level;
481 1.5 deraadt intr_establish(level, ihs);
482 1.5 deraadt }
483 1.4 deraadt
484 1.2 deraadt #define getpte(va) lda(va, ASI_PTE)
485 1.2 deraadt
486 1.2 deraadt /*
487 1.2 deraadt * If we can find a mapping that was established by the rom, use it.
488 1.2 deraadt * Else, create a new mapping.
489 1.2 deraadt */
490 1.2 deraadt void *
491 1.4 deraadt bus_map(pa, len, bustype)
492 1.17 pk struct rom_reg *pa;
493 1.2 deraadt int len;
494 1.4 deraadt int bustype;
495 1.2 deraadt {
496 1.18 pk u_long pf = (u_long)(pa->rr_paddr) >> PGSHIFT;
497 1.2 deraadt u_long va, pte;
498 1.20 christos int pgtype = -1;
499 1.4 deraadt
500 1.4 deraadt switch (bt2pmt[bustype]) {
501 1.4 deraadt case PMAP_OBIO:
502 1.4 deraadt pgtype = PG_OBIO;
503 1.4 deraadt break;
504 1.4 deraadt case PMAP_VME32:
505 1.4 deraadt pgtype = PG_VME32;
506 1.4 deraadt break;
507 1.4 deraadt case PMAP_VME16:
508 1.4 deraadt pgtype = PG_VME16;
509 1.4 deraadt break;
510 1.4 deraadt }
511 1.2 deraadt
512 1.3 deraadt if (len <= NBPG) {
513 1.3 deraadt for (va = OLDMON_STARTVADDR; va < OLDMON_ENDVADDR; va += NBPG) {
514 1.3 deraadt pte = getpte(va);
515 1.4 deraadt if ((pte & PG_V) != 0 && (pte & PG_TYPE) == pgtype &&
516 1.3 deraadt (pte & PG_PFNUM) == pf)
517 1.19 chuck return ((void *)
518 1.19 chuck (va | ((u_long)pa->rr_paddr & PGOFSET)) );
519 1.19 chuck /* note: preserve page offset */
520 1.3 deraadt }
521 1.2 deraadt }
522 1.17 pk return mapiodev(pa, 0, len, bustype);
523 1.2 deraadt }
524 1.2 deraadt
525 1.2 deraadt void *
526 1.4 deraadt bus_tmp(pa, bustype)
527 1.2 deraadt void *pa;
528 1.4 deraadt int bustype;
529 1.2 deraadt {
530 1.3 deraadt vm_offset_t addr = (vm_offset_t)pa & ~PGOFSET;
531 1.4 deraadt int pmtype = bt2pmt[bustype];
532 1.3 deraadt
533 1.13 mycroft pmap_enter(pmap_kernel(), TMPMAP_VA,
534 1.22 pk addr | pmtype | PMAP_NC,
535 1.22 pk VM_PROT_READ | VM_PROT_WRITE, 1);
536 1.19 chuck return ((void *)(TMPMAP_VA | ((u_long) pa & PGOFSET)) );
537 1.2 deraadt }
538 1.2 deraadt
539 1.2 deraadt void
540 1.4 deraadt bus_untmp()
541 1.2 deraadt {
542 1.13 mycroft pmap_remove(pmap_kernel(), TMPMAP_VA, TMPMAP_VA+NBPG);
543 1.1 deraadt }
544