sbus.c revision 1.19 1 1.19 pk /* $NetBSD: sbus.c,v 1.19 1998/03/21 19:55:31 pk Exp $ */
2 1.4 deraadt
3 1.1 deraadt /*
4 1.1 deraadt * Copyright (c) 1992, 1993
5 1.1 deraadt * The Regents of the University of California. All rights reserved.
6 1.1 deraadt *
7 1.1 deraadt * This software was developed by the Computer Systems Engineering group
8 1.1 deraadt * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 deraadt * contributed to Berkeley.
10 1.1 deraadt *
11 1.1 deraadt * All advertising materials mentioning features or use of this software
12 1.1 deraadt * must display the following acknowledgement:
13 1.1 deraadt * This product includes software developed by the University of
14 1.1 deraadt * California, Lawrence Berkeley Laboratory.
15 1.1 deraadt *
16 1.1 deraadt * Redistribution and use in source and binary forms, with or without
17 1.1 deraadt * modification, are permitted provided that the following conditions
18 1.1 deraadt * are met:
19 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
20 1.1 deraadt * notice, this list of conditions and the following disclaimer.
21 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
23 1.1 deraadt * documentation and/or other materials provided with the distribution.
24 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
25 1.1 deraadt * must display the following acknowledgement:
26 1.1 deraadt * This product includes software developed by the University of
27 1.1 deraadt * California, Berkeley and its contributors.
28 1.1 deraadt * 4. Neither the name of the University nor the names of its contributors
29 1.1 deraadt * may be used to endorse or promote products derived from this software
30 1.1 deraadt * without specific prior written permission.
31 1.1 deraadt *
32 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 1.1 deraadt * SUCH DAMAGE.
43 1.1 deraadt *
44 1.1 deraadt * @(#)sbus.c 8.1 (Berkeley) 6/11/93
45 1.1 deraadt */
46 1.1 deraadt
47 1.1 deraadt /*
48 1.1 deraadt * Sbus stuff.
49 1.1 deraadt */
50 1.1 deraadt
51 1.1 deraadt #include <sys/param.h>
52 1.16 pk #include <sys/malloc.h>
53 1.7 christos #include <sys/systm.h>
54 1.1 deraadt #include <sys/device.h>
55 1.17 pk #include <vm/vm.h>
56 1.1 deraadt
57 1.19 pk #include <machine/bus.h>
58 1.19 pk #include <sparc/dev/sbusreg.h>
59 1.19 pk #include <sparc/dev/sbusvar.h>
60 1.19 pk
61 1.19 pk #include <sparc/sparc/iommuvar.h>
62 1.1 deraadt #include <machine/autoconf.h>
63 1.1 deraadt
64 1.1 deraadt
65 1.8 thorpej void sbusreset __P((int));
66 1.8 thorpej
67 1.19 pk static bus_space_tag_t sbus_alloc_bustag __P((struct sbus_softc *));
68 1.19 pk static int sbus_get_intr __P((struct sbus_softc *, int, int *));
69 1.19 pk static int sbus_bus_mmap __P((void *, bus_type_t, bus_addr_t, int));
70 1.19 pk
71 1.19 pk
72 1.1 deraadt /* autoconfiguration driver */
73 1.19 pk int sbus_match_mainbus __P((struct device *, struct cfdata *, void *));
74 1.19 pk int sbus_match_iommu __P((struct device *, struct cfdata *, void *));
75 1.19 pk void sbus_attach_mainbus __P((struct device *, struct device *, void *));
76 1.19 pk void sbus_attach_iommu __P((struct device *, struct device *, void *));
77 1.8 thorpej
78 1.19 pk struct cfattach sbus_mainbus_ca = {
79 1.19 pk sizeof(struct sbus_softc), sbus_match_mainbus, sbus_attach_mainbus
80 1.19 pk };
81 1.19 pk struct cfattach sbus_iommu_ca = {
82 1.19 pk sizeof(struct sbus_softc), sbus_match_iommu, sbus_attach_iommu
83 1.2 deraadt };
84 1.7 christos
85 1.18 thorpej extern struct cfdriver sbus_cd;
86 1.1 deraadt
87 1.19 pk /* If the PROM does not provide the `ranges' property, we make up our own */
88 1.19 pk struct rom_range sbus_translations[] = {
89 1.19 pk /* Assume a maximum of 4 Sbus slots, all mapped to on-board io space */
90 1.19 pk { 0, 0, PMAP_OBIO, SBUS_ADDR(0,0), 1 << 25 },
91 1.19 pk { 1, 0, PMAP_OBIO, SBUS_ADDR(1,0), 1 << 25 },
92 1.19 pk { 2, 0, PMAP_OBIO, SBUS_ADDR(2,0), 1 << 25 },
93 1.19 pk { 3, 0, PMAP_OBIO, SBUS_ADDR(3,0), 1 << 25 }
94 1.19 pk };
95 1.19 pk
96 1.19 pk /*
97 1.19 pk * Child devices receive the Sbus interrupt level in their attach
98 1.19 pk * arguments. We translate these to CPU IPLs using the following
99 1.19 pk * tables. Note: obio bus interrupt levels are identical to the
100 1.19 pk * processor IPL.
101 1.19 pk *
102 1.19 pk * The second set of tables is used when the Sbus interrupt level
103 1.19 pk * cannot be had from the PROM as an `interrupt' property. We then
104 1.19 pk * fall back on the `intr' property which contains the CPU IPL.
105 1.19 pk */
106 1.19 pk
107 1.19 pk /* Translate Sbus interrupt level to processor IPL */
108 1.19 pk static int intr_sbus2ipl_4c[] = {
109 1.19 pk 0, 1, 2, 3, 5, 7, 8, 9
110 1.19 pk };
111 1.19 pk static int intr_sbus2ipl_4m[] = {
112 1.19 pk 0, 2, 3, 5, 7, 9, 11, 13
113 1.19 pk };
114 1.19 pk
115 1.19 pk #if 0
116 1.19 pk /* Table to translate `intr' property values to Sbus interrupt levels */
117 1.19 pk static int intr2sbus_4c[] = {
118 1.19 pk 0, 1, 2, 3, -1, 4, -1, 5, 6, 7, -1, -1, -1, -1, -1
119 1.19 pk };
120 1.19 pk static int intr2sbus_4m[] = {
121 1.19 pk 0, -1, 1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, -1
122 1.19 pk };
123 1.19 pk #endif
124 1.19 pk
125 1.19 pk #define SBUS_INTR_COMPAT 0x80000000
126 1.19 pk
127 1.19 pk
128 1.1 deraadt /*
129 1.1 deraadt * Print the location of some sbus-attached device (called just
130 1.1 deraadt * before attaching that device). If `sbus' is not NULL, the
131 1.1 deraadt * device was found but not configured; print the sbus as well.
132 1.1 deraadt * Return UNCONF (config_find ignores this if the device was configured).
133 1.1 deraadt */
134 1.1 deraadt int
135 1.19 pk sbus_print(args, busname)
136 1.1 deraadt void *args;
137 1.19 pk const char *busname;
138 1.1 deraadt {
139 1.19 pk struct sbus_attach_args *sa = args;
140 1.1 deraadt
141 1.19 pk if (busname)
142 1.19 pk printf("%s at %s", sa->sa_name, busname);
143 1.19 pk printf(" slot %d offset 0x%x", sa->sa_slot, sa->sa_offset);
144 1.19 pk if (sa->sa_pri) {
145 1.19 pk int level = sa->sa_pri;
146 1.19 pk struct sbus_softc *sc =
147 1.19 pk (struct sbus_softc *) sa->sa_bustag->cookie;
148 1.19 pk
149 1.19 pk printf(" level %d", level & ~SBUS_INTR_COMPAT);
150 1.19 pk if ((level & SBUS_INTR_COMPAT) == 0) {
151 1.19 pk int ipl = sc->sc_intr2ipl[level];
152 1.19 pk if (ipl != level)
153 1.19 pk printf(" (ipl %d)", ipl);
154 1.19 pk }
155 1.19 pk }
156 1.1 deraadt return (UNCONF);
157 1.1 deraadt }
158 1.1 deraadt
159 1.3 deraadt int
160 1.19 pk sbus_match_mainbus(parent, cf, aux)
161 1.19 pk struct device *parent;
162 1.19 pk struct cfdata *cf;
163 1.19 pk void *aux;
164 1.19 pk {
165 1.19 pk struct mainbus_attach_args *ma = aux;
166 1.19 pk
167 1.19 pk if (CPU_ISSUN4)
168 1.19 pk return (0);
169 1.19 pk
170 1.19 pk return (strcmp(cf->cf_driver->cd_name, ma->ma_name) == 0);
171 1.19 pk }
172 1.19 pk
173 1.19 pk int
174 1.19 pk sbus_match_iommu(parent, cf, aux)
175 1.3 deraadt struct device *parent;
176 1.14 pk struct cfdata *cf;
177 1.14 pk void *aux;
178 1.3 deraadt {
179 1.19 pk struct iommu_attach_args *ia = aux;
180 1.3 deraadt
181 1.9 pk if (CPU_ISSUN4)
182 1.3 deraadt return (0);
183 1.9 pk
184 1.19 pk return (strcmp(cf->cf_driver->cd_name, ia->iom_name) == 0);
185 1.3 deraadt }
186 1.3 deraadt
187 1.1 deraadt /*
188 1.1 deraadt * Attach an Sbus.
189 1.1 deraadt */
190 1.1 deraadt void
191 1.19 pk sbus_attach_mainbus(parent, self, aux)
192 1.1 deraadt struct device *parent;
193 1.1 deraadt struct device *self;
194 1.1 deraadt void *aux;
195 1.1 deraadt {
196 1.19 pk struct sbus_softc *sc = (struct sbus_softc *)self;
197 1.19 pk struct mainbus_attach_args *ma = aux;
198 1.19 pk int node = ma->ma_node;
199 1.1 deraadt
200 1.1 deraadt /*
201 1.1 deraadt * XXX there is only one Sbus, for now -- do not know how to
202 1.1 deraadt * address children on others
203 1.1 deraadt */
204 1.1 deraadt if (sc->sc_dev.dv_unit > 0) {
205 1.13 christos printf(" unsupported\n");
206 1.1 deraadt return;
207 1.1 deraadt }
208 1.1 deraadt
209 1.19 pk sc->sc_bustag = ma->ma_bustag;
210 1.19 pk sc->sc_dmatag = ma->ma_dmatag;
211 1.19 pk
212 1.19 pk /* Setup interrupt translation tables */
213 1.19 pk sc->sc_intr2ipl = CPU_ISSUN4C
214 1.19 pk ? intr_sbus2ipl_4c
215 1.19 pk : intr_sbus2ipl_4m;
216 1.19 pk
217 1.19 pk #if 0 /* this won't work */
218 1.19 pk sc->sc_intr_compat = CPU_ISSUN4C
219 1.19 pk ? intr2sbus_4c
220 1.19 pk : intr2sbus_4m;
221 1.19 pk #endif
222 1.19 pk
223 1.19 pk /*
224 1.19 pk * Record clock frequency for synchronous SCSI.
225 1.19 pk * IS THIS THE CORRECT DEFAULT??
226 1.19 pk */
227 1.19 pk sc->sc_clockfreq = getpropint(node, "clock-frequency", 25*1000*1000);
228 1.19 pk printf(": clock = %s MHz\n", clockfreq(sc->sc_clockfreq));
229 1.19 pk
230 1.19 pk sbus_attach(sc, "sbus", node, ma->ma_bp, NULL);
231 1.19 pk }
232 1.19 pk
233 1.19 pk void
234 1.19 pk sbus_attach_iommu(parent, self, aux)
235 1.19 pk struct device *parent;
236 1.19 pk struct device *self;
237 1.19 pk void *aux;
238 1.19 pk {
239 1.19 pk struct sbus_softc *sc = (struct sbus_softc *)self;
240 1.19 pk struct iommu_attach_args *ia = aux;
241 1.19 pk int node = ia->iom_node;
242 1.19 pk
243 1.19 pk sc->sc_bustag = ia->iom_bustag;
244 1.19 pk sc->sc_dmatag = ia->iom_dmatag;
245 1.19 pk
246 1.19 pk /* Setup interrupt translation tables */
247 1.19 pk sc->sc_intr2ipl = CPU_ISSUN4C ? intr_sbus2ipl_4c : intr_sbus2ipl_4m;
248 1.19 pk
249 1.19 pk #if 0 /* this won't work */
250 1.19 pk sc->sc_intr_compat = CPU_ISSUN4C ? intr2sbus_4c : intr2sbus_4m;
251 1.19 pk #endif
252 1.19 pk
253 1.1 deraadt /*
254 1.1 deraadt * Record clock frequency for synchronous SCSI.
255 1.1 deraadt * IS THIS THE CORRECT DEFAULT??
256 1.1 deraadt */
257 1.1 deraadt sc->sc_clockfreq = getpropint(node, "clock-frequency", 25*1000*1000);
258 1.13 christos printf(": clock = %s MHz\n", clockfreq(sc->sc_clockfreq));
259 1.10 abrown
260 1.19 pk sbus_attach(sc, "sbus", node, ia->iom_bp, NULL);
261 1.19 pk }
262 1.19 pk
263 1.19 pk void
264 1.19 pk sbus_attach(sc, busname, busnode, bp, specials)
265 1.19 pk struct sbus_softc *sc;
266 1.19 pk char *busname;
267 1.19 pk int busnode;
268 1.19 pk struct bootpath *bp;
269 1.19 pk const char * const *specials;
270 1.19 pk {
271 1.19 pk int node0, node, error;
272 1.19 pk const char *sp;
273 1.19 pk const char *const *ssp;
274 1.19 pk bus_space_tag_t sbt;
275 1.19 pk struct sbus_attach_args sa;
276 1.19 pk
277 1.19 pk sbt = sbus_alloc_bustag(sc);
278 1.19 pk
279 1.10 abrown /*
280 1.10 abrown * Get the SBus burst transfer size if burst transfers are supported
281 1.10 abrown */
282 1.19 pk sc->sc_burst = getpropint(busnode, "burst-sizes", 0);
283 1.1 deraadt
284 1.19 pk /* Propagate bootpath */
285 1.19 pk if (bp != NULL && strcmp(bp->name, busname) == 0)
286 1.19 pk bp++;
287 1.1 deraadt else
288 1.19 pk bp = NULL;
289 1.1 deraadt
290 1.19 pk /*
291 1.19 pk * Collect address translations from the OBP.
292 1.19 pk */
293 1.19 pk error = getpropA(busnode, "ranges", sizeof(struct rom_range),
294 1.19 pk &sc->sc_nrange, (void **)&sc->sc_range);
295 1.19 pk switch (error) {
296 1.19 pk case 0:
297 1.19 pk break;
298 1.19 pk case ENOENT:
299 1.19 pk /* Fall back to our own `range' construction */
300 1.19 pk sc->sc_range = sbus_translations;
301 1.19 pk sc->sc_nrange =
302 1.19 pk sizeof(sbus_translations)/sizeof(sbus_translations[0]);
303 1.19 pk break;
304 1.19 pk default:
305 1.19 pk panic("%s: error getting ranges property", sc->sc_dev.dv_xname);
306 1.16 pk }
307 1.9 pk
308 1.1 deraadt /*
309 1.1 deraadt * Loop through ROM children, fixing any relative addresses
310 1.1 deraadt * and then configuring each device.
311 1.19 pk * `specials' is an array of device names that are treated
312 1.19 pk * specially:
313 1.1 deraadt */
314 1.19 pk node0 = firstchild(busnode);
315 1.19 pk for (ssp = specials ; ssp != NULL && *(sp = *ssp) != 0; ssp++) {
316 1.19 pk if ((node = findnode(node0, sp)) == 0) {
317 1.19 pk panic("could not find %s amongst %s devices",
318 1.19 pk sp, busname);
319 1.19 pk }
320 1.19 pk
321 1.19 pk if (sbus_setup_attach_args(sc, sbt, sc->sc_dmatag,
322 1.19 pk node, bp, &sa) != 0) {
323 1.19 pk panic("sbus_attach: %s: incomplete", sp);
324 1.19 pk }
325 1.19 pk (void) config_found(&sc->sc_dev, (void *)&sa, sbus_print);
326 1.19 pk }
327 1.19 pk
328 1.19 pk for (node = node0; node; node = nextsibling(node)) {
329 1.19 pk char *name = getpropstring(node, "name");
330 1.19 pk for (ssp = specials, sp = NULL;
331 1.19 pk ssp != NULL && (sp = *ssp) != NULL;
332 1.19 pk ssp++)
333 1.19 pk if (strcmp(name, sp) == 0)
334 1.19 pk break;
335 1.19 pk
336 1.19 pk if (sp != NULL)
337 1.19 pk /* Already configured as an "early" device */
338 1.19 pk continue;
339 1.19 pk
340 1.19 pk if (sbus_setup_attach_args(sc, sbt, sc->sc_dmatag,
341 1.19 pk node, bp, &sa) != 0) {
342 1.19 pk printf("sbus_attach: %s: incomplete\n", name);
343 1.1 deraadt continue;
344 1.19 pk }
345 1.19 pk (void) config_found(&sc->sc_dev, (void *)&sa, sbus_print);
346 1.19 pk }
347 1.19 pk }
348 1.9 pk
349 1.19 pk int
350 1.19 pk sbus_setup_attach_args(sc, bustag, dmatag, node, bp, sa)
351 1.19 pk struct sbus_softc *sc;
352 1.19 pk bus_space_tag_t bustag;
353 1.19 pk bus_dma_tag_t dmatag;
354 1.19 pk int node;
355 1.19 pk struct bootpath *bp;
356 1.19 pk struct sbus_attach_args *sa;
357 1.19 pk {
358 1.19 pk struct rom_reg romreg;
359 1.19 pk int base;
360 1.19 pk int error;
361 1.19 pk
362 1.19 pk bzero(sa, sizeof(struct sbus_attach_args));
363 1.19 pk sa->sa_name = getpropstring(node, "name");
364 1.19 pk sa->sa_bustag = bustag;
365 1.19 pk sa->sa_dmatag = dmatag;
366 1.19 pk sa->sa_node = node;
367 1.19 pk sa->sa_bp = bp;
368 1.19 pk
369 1.19 pk if ((error = getprop_reg1(node, &romreg)) != 0)
370 1.19 pk return (error);
371 1.19 pk
372 1.19 pk /* We pass only the first "reg" property */
373 1.19 pk base = (int)romreg.rr_paddr;
374 1.19 pk if (SBUS_ABS(base)) {
375 1.19 pk sa->sa_slot = SBUS_ABS_TO_SLOT(base);
376 1.19 pk sa->sa_offset = SBUS_ABS_TO_OFFSET(base);
377 1.19 pk } else {
378 1.19 pk sa->sa_slot = romreg.rr_iospace;
379 1.19 pk sa->sa_offset = base;
380 1.9 pk }
381 1.19 pk sa->sa_size = romreg.rr_len;
382 1.19 pk
383 1.19 pk if ((error = sbus_get_intr(sc, node, &sa->sa_pri)) != 0)
384 1.19 pk return (error);
385 1.19 pk
386 1.19 pk if ((error = getprop_address1(node, &sa->sa_promvaddr)) != 0)
387 1.19 pk return (error);
388 1.19 pk
389 1.19 pk return (0);
390 1.9 pk }
391 1.9 pk
392 1.19 pk int
393 1.19 pk sbus_bus_map(t, slot, offset, size, flags, vaddr, hp)
394 1.19 pk bus_space_tag_t t;
395 1.19 pk int slot, offset, size, flags;
396 1.19 pk vm_offset_t vaddr;
397 1.19 pk bus_space_handle_t *hp;
398 1.9 pk {
399 1.19 pk struct sbus_softc *sc = t->cookie;
400 1.19 pk int i;
401 1.19 pk
402 1.19 pk for (i = 0; i < sc->sc_nrange; i++) {
403 1.19 pk bus_addr_t paddr;
404 1.19 pk bus_type_t iospace;
405 1.19 pk
406 1.19 pk if (sc->sc_range[i].cspace != slot)
407 1.19 pk continue;
408 1.19 pk
409 1.19 pk /* We've found the connection to the parent bus */
410 1.19 pk paddr = sc->sc_range[i].poffset + offset;
411 1.19 pk iospace = sc->sc_range[i].pspace;
412 1.19 pk return (bus_space_map2(sc->sc_bustag, iospace, paddr,
413 1.19 pk size, flags, vaddr, hp));
414 1.19 pk }
415 1.19 pk
416 1.19 pk return (EINVAL);
417 1.19 pk }
418 1.9 pk
419 1.19 pk int
420 1.19 pk sbus_bus_mmap(cookie, btype, paddr, flags)
421 1.19 pk void *cookie;
422 1.19 pk bus_type_t btype;
423 1.19 pk bus_addr_t paddr;
424 1.19 pk int flags;
425 1.19 pk {
426 1.19 pk int slot = (int)btype;
427 1.19 pk int offset = (int)paddr;
428 1.19 pk struct sbus_softc *sc = cookie;
429 1.19 pk int i;
430 1.19 pk
431 1.19 pk for (i = 0; i < sc->sc_nrange; i++) {
432 1.19 pk bus_addr_t paddr;
433 1.19 pk bus_addr_t iospace;
434 1.9 pk
435 1.19 pk if (sc->sc_range[i].cspace != slot)
436 1.19 pk continue;
437 1.9 pk
438 1.19 pk paddr = sc->sc_range[i].poffset + offset;
439 1.19 pk iospace = (bus_addr_t)sc->sc_range[i].pspace;
440 1.19 pk return (bus_space_mmap(sc->sc_bustag, iospace, paddr, flags));
441 1.1 deraadt }
442 1.19 pk
443 1.19 pk return (-1);
444 1.1 deraadt }
445 1.1 deraadt
446 1.19 pk
447 1.1 deraadt /*
448 1.1 deraadt * Each attached device calls sbus_establish after it initializes
449 1.1 deraadt * its sbusdev portion.
450 1.1 deraadt */
451 1.1 deraadt void
452 1.1 deraadt sbus_establish(sd, dev)
453 1.1 deraadt register struct sbusdev *sd;
454 1.1 deraadt register struct device *dev;
455 1.1 deraadt {
456 1.9 pk register struct sbus_softc *sc;
457 1.9 pk register struct device *curdev;
458 1.9 pk
459 1.9 pk /*
460 1.9 pk * We have to look for the sbus by name, since it is not necessarily
461 1.9 pk * our immediate parent (i.e. sun4m /iommu/sbus/espdma/esp)
462 1.9 pk * We don't just use the device structure of the above-attached
463 1.9 pk * sbus, since we might (in the future) support multiple sbus's.
464 1.9 pk */
465 1.9 pk for (curdev = dev->dv_parent; ; curdev = curdev->dv_parent) {
466 1.9 pk if (!curdev || !curdev->dv_xname)
467 1.15 pk panic("sbus_establish: can't find sbus parent for %s",
468 1.15 pk sd->sd_dev->dv_xname
469 1.15 pk ? sd->sd_dev->dv_xname
470 1.15 pk : "<unknown>" );
471 1.9 pk
472 1.9 pk if (strncmp(curdev->dv_xname, "sbus", 4) == 0)
473 1.15 pk break;
474 1.9 pk }
475 1.9 pk sc = (struct sbus_softc *) curdev;
476 1.1 deraadt
477 1.1 deraadt sd->sd_dev = dev;
478 1.1 deraadt sd->sd_bchain = sc->sc_sbdev;
479 1.1 deraadt sc->sc_sbdev = sd;
480 1.1 deraadt }
481 1.1 deraadt
482 1.1 deraadt /*
483 1.1 deraadt * Reset the given sbus. (???)
484 1.1 deraadt */
485 1.1 deraadt void
486 1.1 deraadt sbusreset(sbus)
487 1.1 deraadt int sbus;
488 1.1 deraadt {
489 1.1 deraadt register struct sbusdev *sd;
490 1.8 thorpej struct sbus_softc *sc = sbus_cd.cd_devs[sbus];
491 1.1 deraadt struct device *dev;
492 1.1 deraadt
493 1.13 christos printf("reset %s:", sc->sc_dev.dv_xname);
494 1.1 deraadt for (sd = sc->sc_sbdev; sd != NULL; sd = sd->sd_bchain) {
495 1.1 deraadt if (sd->sd_reset) {
496 1.1 deraadt dev = sd->sd_dev;
497 1.1 deraadt (*sd->sd_reset)(dev);
498 1.13 christos printf(" %s", dev->dv_xname);
499 1.1 deraadt }
500 1.1 deraadt }
501 1.1 deraadt }
502 1.19 pk
503 1.19 pk
504 1.19 pk /*
505 1.19 pk * Get interrupt attributes for an Sbus device.
506 1.19 pk */
507 1.19 pk int
508 1.19 pk sbus_get_intr(sc, node, ip)
509 1.19 pk struct sbus_softc *sc;
510 1.19 pk int node;
511 1.19 pk int *ip;
512 1.19 pk {
513 1.19 pk struct rom_intr *rip;
514 1.19 pk int *ipl;
515 1.19 pk int n;
516 1.19 pk
517 1.19 pk /*
518 1.19 pk * The `interrupts' property contains the Sbus interrupt level.
519 1.19 pk */
520 1.19 pk ipl = NULL;
521 1.19 pk if (getpropA(node, "interrupts", sizeof(int), &n, (void **)&ipl) == 0) {
522 1.19 pk *ip = ipl[0];
523 1.19 pk free(ipl, M_DEVBUF);
524 1.19 pk return (0);
525 1.19 pk }
526 1.19 pk
527 1.19 pk /*
528 1.19 pk * Fall back on `intr' property.
529 1.19 pk */
530 1.19 pk rip = NULL;
531 1.19 pk switch (getpropA(node, "intr", sizeof(*rip), &n, (void **)&rip)) {
532 1.19 pk case 0:
533 1.19 pk *ip = (rip[0].int_pri & 0xf) | SBUS_INTR_COMPAT;
534 1.19 pk free(rip, M_DEVBUF);
535 1.19 pk return (0);
536 1.19 pk case ENOENT:
537 1.19 pk *ip = 0;
538 1.19 pk return (0);
539 1.19 pk }
540 1.19 pk
541 1.19 pk return (-1);
542 1.19 pk }
543 1.19 pk
544 1.19 pk
545 1.19 pk /*
546 1.19 pk * Install an interrupt handler for an Sbus device.
547 1.19 pk */
548 1.19 pk void *
549 1.19 pk sbus_intr_establish(cookie, level, flags, handler, arg)
550 1.19 pk void *cookie;
551 1.19 pk int level;
552 1.19 pk int flags;
553 1.19 pk int (*handler) __P((void *));
554 1.19 pk void *arg;
555 1.19 pk {
556 1.19 pk struct sbus_softc *sc = cookie;
557 1.19 pk struct intrhand *ih;
558 1.19 pk int ipl;
559 1.19 pk
560 1.19 pk ih = (struct intrhand *)
561 1.19 pk malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT);
562 1.19 pk if (ih == NULL)
563 1.19 pk return (NULL);
564 1.19 pk
565 1.19 pk if ((flags & BUS_INTR_ESTABLISH_SOFTINTR) != 0)
566 1.19 pk ipl = level;
567 1.19 pk else if ((level & SBUS_INTR_COMPAT) != 0)
568 1.19 pk ipl = level & ~SBUS_INTR_COMPAT;
569 1.19 pk else
570 1.19 pk ipl = sc->sc_intr2ipl[level];
571 1.19 pk
572 1.19 pk ih->ih_fun = handler;
573 1.19 pk ih->ih_arg = arg;
574 1.19 pk if ((flags & BUS_INTR_ESTABLISH_FASTTRAP) != 0)
575 1.19 pk intr_fasttrap(ipl, (void (*)__P((void)))handler);
576 1.19 pk else
577 1.19 pk intr_establish(ipl, ih);
578 1.19 pk return (ih);
579 1.19 pk }
580 1.19 pk
581 1.19 pk static bus_space_tag_t
582 1.19 pk sbus_alloc_bustag(sc)
583 1.19 pk struct sbus_softc *sc;
584 1.19 pk {
585 1.19 pk bus_space_tag_t sbt;
586 1.19 pk
587 1.19 pk sbt = (bus_space_tag_t)
588 1.19 pk malloc(sizeof(struct sparc_bus_space_tag), M_DEVBUF, M_NOWAIT);
589 1.19 pk if (sbt == NULL)
590 1.19 pk return (NULL);
591 1.19 pk
592 1.19 pk bzero(sbt, sizeof *sbt);
593 1.19 pk sbt->cookie = sc;
594 1.19 pk #if notyet
595 1.19 pk sbt->sparc_bus_map = _sbus_bus_map;
596 1.19 pk #endif
597 1.19 pk sbt->sparc_bus_mmap = sbus_bus_mmap;
598 1.19 pk sbt->sparc_intr_establish = sbus_intr_establish;
599 1.19 pk return (sbt);
600 1.19 pk }
601 1.19 pk
602