ebus.c revision 1.43 1 1.43 pk /* $NetBSD: ebus.c,v 1.43 2004/03/17 17:04:59 pk Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.29 mrg * Copyright (c) 1999, 2000, 2001 Matthew R. Green
5 1.1 mrg * All rights reserved.
6 1.1 mrg *
7 1.1 mrg * Redistribution and use in source and binary forms, with or without
8 1.1 mrg * modification, are permitted provided that the following conditions
9 1.1 mrg * are met:
10 1.1 mrg * 1. Redistributions of source code must retain the above copyright
11 1.1 mrg * notice, this list of conditions and the following disclaimer.
12 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mrg * notice, this list of conditions and the following disclaimer in the
14 1.1 mrg * documentation and/or other materials provided with the distribution.
15 1.1 mrg * 3. The name of the author may not be used to endorse or promote products
16 1.1 mrg * derived from this software without specific prior written permission.
17 1.1 mrg *
18 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 1.1 mrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 1.1 mrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 1.1 mrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 1.1 mrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.1 mrg * SUCH DAMAGE.
29 1.1 mrg */
30 1.40 lukem
31 1.40 lukem #include <sys/cdefs.h>
32 1.43 pk __KERNEL_RCSID(0, "$NetBSD: ebus.c,v 1.43 2004/03/17 17:04:59 pk Exp $");
33 1.1 mrg
34 1.8 mrg #include "opt_ddb.h"
35 1.8 mrg
36 1.1 mrg /*
37 1.1 mrg * UltraSPARC 5 and beyond ebus support.
38 1.8 mrg *
39 1.21 mrg * note that this driver is not complete:
40 1.21 mrg * - interrupt establish is written and appears to work
41 1.8 mrg * - bus map code is written and appears to work
42 1.38 wiz * - ebus2 DMA code is completely unwritten, we just punt to
43 1.29 mrg * the iommu.
44 1.1 mrg */
45 1.1 mrg
46 1.1 mrg #ifdef DEBUG
47 1.8 mrg #define EDB_PROM 0x01
48 1.8 mrg #define EDB_CHILD 0x02
49 1.8 mrg #define EDB_INTRMAP 0x04
50 1.8 mrg #define EDB_BUSMAP 0x08
51 1.29 mrg int ebus_debug = 0;
52 1.1 mrg #define DPRINTF(l, s) do { if (ebus_debug & l) printf s; } while (0)
53 1.1 mrg #else
54 1.1 mrg #define DPRINTF(l, s)
55 1.1 mrg #endif
56 1.1 mrg
57 1.1 mrg #include <sys/param.h>
58 1.1 mrg #include <sys/conf.h>
59 1.1 mrg #include <sys/device.h>
60 1.8 mrg #include <sys/errno.h>
61 1.8 mrg #include <sys/extent.h>
62 1.1 mrg #include <sys/malloc.h>
63 1.1 mrg #include <sys/systm.h>
64 1.8 mrg #include <sys/time.h>
65 1.1 mrg
66 1.1 mrg #define _SPARC_BUS_DMA_PRIVATE
67 1.1 mrg #include <machine/bus.h>
68 1.1 mrg #include <machine/autoconf.h>
69 1.23 eeh #include <machine/openfirm.h>
70 1.1 mrg
71 1.1 mrg #include <dev/pci/pcivar.h>
72 1.1 mrg #include <dev/pci/pcireg.h>
73 1.1 mrg #include <dev/pci/pcidevs.h>
74 1.1 mrg
75 1.8 mrg #include <sparc64/dev/iommureg.h>
76 1.8 mrg #include <sparc64/dev/iommuvar.h>
77 1.8 mrg #include <sparc64/dev/psychoreg.h>
78 1.8 mrg #include <sparc64/dev/psychovar.h>
79 1.29 mrg #include <dev/ebus/ebusreg.h>
80 1.31 mrg #include <dev/ebus/ebusvar.h>
81 1.8 mrg #include <sparc64/sparc64/cache.h>
82 1.1 mrg
83 1.29 mrg struct ebus_softc {
84 1.29 mrg struct device sc_dev;
85 1.29 mrg
86 1.29 mrg int sc_node;
87 1.29 mrg
88 1.29 mrg bus_space_tag_t sc_memtag; /* from pci */
89 1.29 mrg bus_space_tag_t sc_iotag; /* from pci */
90 1.29 mrg bus_space_tag_t sc_childbustag; /* pass to children */
91 1.29 mrg bus_dma_tag_t sc_dmatag;
92 1.29 mrg
93 1.29 mrg struct ebus_ranges *sc_range;
94 1.29 mrg struct ebus_interrupt_map *sc_intmap;
95 1.29 mrg struct ebus_interrupt_map_mask sc_intmapmask;
96 1.29 mrg
97 1.29 mrg int sc_nrange; /* counters */
98 1.29 mrg int sc_nintmap;
99 1.29 mrg };
100 1.29 mrg
101 1.1 mrg int ebus_match __P((struct device *, struct cfdata *, void *));
102 1.1 mrg void ebus_attach __P((struct device *, struct device *, void *));
103 1.1 mrg
104 1.33 thorpej CFATTACH_DECL(ebus, sizeof(struct ebus_softc),
105 1.34 thorpej ebus_match, ebus_attach, NULL, NULL);
106 1.1 mrg
107 1.29 mrg bus_space_tag_t ebus_alloc_bus_tag __P((struct ebus_softc *, int));
108 1.29 mrg
109 1.1 mrg int ebus_setup_attach_args __P((struct ebus_softc *, int,
110 1.1 mrg struct ebus_attach_args *));
111 1.1 mrg void ebus_destroy_attach_args __P((struct ebus_attach_args *));
112 1.1 mrg int ebus_print __P((void *, const char *));
113 1.3 mrg void ebus_find_ino __P((struct ebus_softc *, struct ebus_attach_args *));
114 1.10 mrg int ebus_find_node __P((struct pci_attach_args *));
115 1.1 mrg
116 1.8 mrg /*
117 1.38 wiz * here are our bus space and bus DMA routines.
118 1.8 mrg */
119 1.27 eeh static paddr_t ebus_bus_mmap __P((bus_space_tag_t, bus_addr_t, off_t, int, int));
120 1.30 eeh static int _ebus_bus_map __P((bus_space_tag_t, bus_addr_t, bus_size_t, int,
121 1.30 eeh vaddr_t, bus_space_handle_t *));
122 1.36 pk static void *ebus_intr_establish __P((bus_space_tag_t, int, int,
123 1.35 pk int (*) __P((void *)), void *, void(*)__P((void))));
124 1.8 mrg
125 1.1 mrg int
126 1.1 mrg ebus_match(parent, match, aux)
127 1.1 mrg struct device *parent;
128 1.1 mrg struct cfdata *match;
129 1.1 mrg void *aux;
130 1.1 mrg {
131 1.1 mrg struct pci_attach_args *pa = aux;
132 1.24 eeh char name[10];
133 1.23 eeh int node;
134 1.1 mrg
135 1.23 eeh /* Only attach if there's a PROM node. */
136 1.23 eeh node = PCITAG_NODE(pa->pa_tag);
137 1.23 eeh if (node == -1) return (0);
138 1.23 eeh
139 1.23 eeh /* Match a real ebus */
140 1.24 eeh OF_getprop(node, "name", &name, sizeof(name));
141 1.1 mrg if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
142 1.16 pk PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
143 1.24 eeh PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_EBUS &&
144 1.25 eeh strcmp(name, "ebus") == 0)
145 1.25 eeh return (1);
146 1.25 eeh
147 1.25 eeh /* Or a real ebus III */
148 1.25 eeh if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
149 1.25 eeh PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
150 1.25 eeh PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_EBUSIII &&
151 1.24 eeh strcmp(name, "ebus") == 0)
152 1.1 mrg return (1);
153 1.1 mrg
154 1.23 eeh /* Or a PCI-ISA bridge XXX I hope this is on-board. */
155 1.23 eeh if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
156 1.23 eeh PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) {
157 1.23 eeh return (1);
158 1.23 eeh }
159 1.23 eeh
160 1.1 mrg return (0);
161 1.1 mrg }
162 1.1 mrg
163 1.1 mrg /*
164 1.1 mrg * attach an ebus and all it's children. this code is modeled
165 1.1 mrg * after the sbus code which does similar things.
166 1.1 mrg */
167 1.1 mrg void
168 1.1 mrg ebus_attach(parent, self, aux)
169 1.1 mrg struct device *parent, *self;
170 1.1 mrg void *aux;
171 1.1 mrg {
172 1.1 mrg struct ebus_softc *sc = (struct ebus_softc *)self;
173 1.1 mrg struct pci_attach_args *pa = aux;
174 1.1 mrg struct ebus_attach_args eba;
175 1.1 mrg struct ebus_interrupt_map_mask *immp;
176 1.16 pk int node, nmapmask, error;
177 1.1 mrg char devinfo[256];
178 1.1 mrg
179 1.1 mrg printf("\n");
180 1.1 mrg
181 1.1 mrg pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
182 1.1 mrg printf("%s: %s, revision 0x%02x\n", self->dv_xname, devinfo,
183 1.1 mrg PCI_REVISION(pa->pa_class));
184 1.1 mrg
185 1.23 eeh sc->sc_memtag = pa->pa_memt;
186 1.23 eeh sc->sc_iotag = pa->pa_iot;
187 1.1 mrg sc->sc_childbustag = ebus_alloc_bus_tag(sc, PCI_MEMORY_BUS_SPACE);
188 1.29 mrg sc->sc_dmatag = pa->pa_dmat;
189 1.1 mrg
190 1.23 eeh node = PCITAG_NODE(pa->pa_tag);
191 1.23 eeh if (node == -1)
192 1.1 mrg panic("could not find ebus node");
193 1.1 mrg
194 1.1 mrg sc->sc_node = node;
195 1.1 mrg
196 1.1 mrg /*
197 1.1 mrg * fill in our softc with information from the prom
198 1.1 mrg */
199 1.3 mrg sc->sc_intmap = NULL;
200 1.3 mrg sc->sc_range = NULL;
201 1.43 pk error = prom_getprop(node, "interrupt-map",
202 1.16 pk sizeof(struct ebus_interrupt_map),
203 1.41 mrg &sc->sc_nintmap, &sc->sc_intmap);
204 1.16 pk switch (error) {
205 1.16 pk case 0:
206 1.16 pk immp = &sc->sc_intmapmask;
207 1.43 pk error = prom_getprop(node, "interrupt-map-mask",
208 1.16 pk sizeof(struct ebus_interrupt_map_mask), &nmapmask,
209 1.41 mrg &immp);
210 1.16 pk if (error)
211 1.16 pk panic("could not get ebus interrupt-map-mask");
212 1.16 pk if (nmapmask != 1)
213 1.16 pk panic("ebus interrupt-map-mask is broken");
214 1.16 pk break;
215 1.16 pk case ENOENT:
216 1.16 pk break;
217 1.16 pk default:
218 1.16 pk panic("ebus interrupt-map: error %d", error);
219 1.16 pk break;
220 1.16 pk }
221 1.1 mrg
222 1.43 pk error = prom_getprop(node, "ranges", sizeof(struct ebus_ranges),
223 1.41 mrg &sc->sc_nrange, &sc->sc_range);
224 1.16 pk if (error)
225 1.16 pk panic("ebus ranges: error %d", error);
226 1.1 mrg
227 1.1 mrg /*
228 1.1 mrg * now attach all our children
229 1.1 mrg */
230 1.1 mrg DPRINTF(EDB_CHILD, ("ebus node %08x, searching children...\n", node));
231 1.1 mrg for (node = firstchild(node); node; node = nextsibling(node)) {
232 1.43 pk char *name = prom_getpropstring(node, "name");
233 1.1 mrg
234 1.1 mrg if (ebus_setup_attach_args(sc, node, &eba) != 0) {
235 1.1 mrg printf("ebus_attach: %s: incomplete\n", name);
236 1.1 mrg continue;
237 1.6 mrg } else {
238 1.21 mrg DPRINTF(EDB_CHILD, ("- found child `%s', attaching\n",
239 1.21 mrg eba.ea_name));
240 1.6 mrg (void)config_found(self, &eba, ebus_print);
241 1.1 mrg }
242 1.1 mrg ebus_destroy_attach_args(&eba);
243 1.1 mrg }
244 1.1 mrg }
245 1.1 mrg
246 1.1 mrg int
247 1.1 mrg ebus_setup_attach_args(sc, node, ea)
248 1.1 mrg struct ebus_softc *sc;
249 1.1 mrg int node;
250 1.1 mrg struct ebus_attach_args *ea;
251 1.1 mrg {
252 1.1 mrg int n, rv;
253 1.1 mrg
254 1.42 martin memset(ea, 0, sizeof(struct ebus_attach_args));
255 1.43 pk rv = prom_getprop(node, "name", 1, &n, &ea->ea_name);
256 1.1 mrg if (rv != 0)
257 1.1 mrg return (rv);
258 1.1 mrg ea->ea_name[n] = '\0';
259 1.1 mrg
260 1.1 mrg ea->ea_node = node;
261 1.1 mrg ea->ea_bustag = sc->sc_childbustag;
262 1.1 mrg ea->ea_dmatag = sc->sc_dmatag;
263 1.1 mrg
264 1.43 pk rv = prom_getprop(node, "reg", sizeof(struct ebus_regs), &ea->ea_nreg,
265 1.41 mrg &ea->ea_reg);
266 1.1 mrg if (rv)
267 1.1 mrg return (rv);
268 1.1 mrg
269 1.43 pk rv = prom_getprop(node, "address", sizeof(u_int32_t), &ea->ea_nvaddr,
270 1.41 mrg &ea->ea_vaddr);
271 1.1 mrg if (rv != ENOENT) {
272 1.1 mrg if (rv)
273 1.1 mrg return (rv);
274 1.1 mrg
275 1.31 mrg if (ea->ea_nreg != ea->ea_nvaddr)
276 1.1 mrg printf("ebus loses: device %s: %d regs and %d addrs\n",
277 1.31 mrg ea->ea_name, ea->ea_nreg, ea->ea_nvaddr);
278 1.3 mrg } else
279 1.31 mrg ea->ea_nvaddr = 0;
280 1.1 mrg
281 1.43 pk if (prom_getprop(node, "interrupts", sizeof(u_int32_t), &ea->ea_nintr,
282 1.41 mrg &ea->ea_intr))
283 1.31 mrg ea->ea_nintr = 0;
284 1.16 pk else
285 1.3 mrg ebus_find_ino(sc, ea);
286 1.1 mrg
287 1.1 mrg return (0);
288 1.1 mrg }
289 1.1 mrg
290 1.1 mrg void
291 1.1 mrg ebus_destroy_attach_args(ea)
292 1.1 mrg struct ebus_attach_args *ea;
293 1.1 mrg {
294 1.1 mrg
295 1.1 mrg if (ea->ea_name)
296 1.1 mrg free((void *)ea->ea_name, M_DEVBUF);
297 1.31 mrg if (ea->ea_reg)
298 1.31 mrg free((void *)ea->ea_reg, M_DEVBUF);
299 1.31 mrg if (ea->ea_intr)
300 1.31 mrg free((void *)ea->ea_intr, M_DEVBUF);
301 1.31 mrg if (ea->ea_vaddr)
302 1.31 mrg free((void *)ea->ea_vaddr, M_DEVBUF);
303 1.1 mrg }
304 1.1 mrg
305 1.1 mrg int
306 1.1 mrg ebus_print(aux, p)
307 1.1 mrg void *aux;
308 1.1 mrg const char *p;
309 1.1 mrg {
310 1.1 mrg struct ebus_attach_args *ea = aux;
311 1.4 mrg int i;
312 1.1 mrg
313 1.1 mrg if (p)
314 1.37 thorpej aprint_normal("%s at %s", ea->ea_name, p);
315 1.31 mrg for (i = 0; i < ea->ea_nreg; i++)
316 1.37 thorpej aprint_normal("%s %x-%x", i == 0 ? " addr" : ",",
317 1.31 mrg ea->ea_reg[i].lo,
318 1.31 mrg ea->ea_reg[i].lo + ea->ea_reg[i].size - 1);
319 1.31 mrg for (i = 0; i < ea->ea_nintr; i++)
320 1.37 thorpej aprint_normal(" ipl %d", ea->ea_intr[i]);
321 1.1 mrg return (UNCONF);
322 1.3 mrg }
323 1.3 mrg
324 1.23 eeh
325 1.3 mrg /*
326 1.3 mrg * find the INO values for each interrupt and fill them in.
327 1.3 mrg *
328 1.3 mrg * for each "reg" property of this device, mask it's hi and lo
329 1.3 mrg * values with the "interrupt-map-mask"'s hi/lo values, and also
330 1.3 mrg * mask the interrupt number with the interrupt mask. search the
331 1.3 mrg * "interrupt-map" list for matching values of hi, lo and interrupt
332 1.3 mrg * to give the INO for this interrupt.
333 1.3 mrg */
334 1.3 mrg void
335 1.3 mrg ebus_find_ino(sc, ea)
336 1.3 mrg struct ebus_softc *sc;
337 1.3 mrg struct ebus_attach_args *ea;
338 1.3 mrg {
339 1.3 mrg u_int32_t hi, lo, intr;
340 1.3 mrg int i, j, k;
341 1.3 mrg
342 1.16 pk if (sc->sc_nintmap == 0) {
343 1.31 mrg for (i = 0; i < ea->ea_nintr; i++) {
344 1.31 mrg OF_mapintr(ea->ea_node, &ea->ea_intr[i],
345 1.31 mrg sizeof(ea->ea_intr[0]),
346 1.31 mrg sizeof(ea->ea_intr[0]));
347 1.23 eeh }
348 1.16 pk return;
349 1.16 pk }
350 1.16 pk
351 1.21 mrg DPRINTF(EDB_INTRMAP,
352 1.31 mrg ("ebus_find_ino: searching %d interrupts", ea->ea_nintr));
353 1.16 pk
354 1.31 mrg for (j = 0; j < ea->ea_nintr; j++) {
355 1.16 pk
356 1.31 mrg intr = ea->ea_intr[j] & sc->sc_intmapmask.intr;
357 1.3 mrg
358 1.21 mrg DPRINTF(EDB_INTRMAP,
359 1.31 mrg ("; intr %x masked to %x", ea->ea_intr[j], intr));
360 1.31 mrg for (i = 0; i < ea->ea_nreg; i++) {
361 1.31 mrg hi = ea->ea_reg[i].hi & sc->sc_intmapmask.hi;
362 1.31 mrg lo = ea->ea_reg[i].lo & sc->sc_intmapmask.lo;
363 1.3 mrg
364 1.21 mrg DPRINTF(EDB_INTRMAP,
365 1.21 mrg ("; reg hi.lo %08x.%08x masked to %08x.%08x",
366 1.31 mrg ea->ea_reg[i].hi, ea->ea_reg[i].lo, hi, lo));
367 1.3 mrg for (k = 0; k < sc->sc_nintmap; k++) {
368 1.21 mrg DPRINTF(EDB_INTRMAP,
369 1.21 mrg ("; checking hi.lo %08x.%08x intr %x",
370 1.21 mrg sc->sc_intmap[k].hi, sc->sc_intmap[k].lo,
371 1.21 mrg sc->sc_intmap[k].intr));
372 1.3 mrg if (hi == sc->sc_intmap[k].hi &&
373 1.3 mrg lo == sc->sc_intmap[k].lo &&
374 1.3 mrg intr == sc->sc_intmap[k].intr) {
375 1.31 mrg ea->ea_intr[j] =
376 1.21 mrg sc->sc_intmap[k].cintr;
377 1.21 mrg DPRINTF(EDB_INTRMAP,
378 1.21 mrg ("; FOUND IT! changing to %d\n",
379 1.21 mrg sc->sc_intmap[k].cintr));
380 1.3 mrg goto next_intr;
381 1.3 mrg }
382 1.3 mrg }
383 1.3 mrg }
384 1.22 mrg next_intr:;
385 1.3 mrg }
386 1.1 mrg }
387 1.1 mrg
388 1.8 mrg /*
389 1.29 mrg * bus space support. <sparc64/dev/psychoreg.h> has a discussion
390 1.29 mrg * about PCI physical addresses, which also applies to ebus.
391 1.8 mrg */
392 1.8 mrg bus_space_tag_t
393 1.8 mrg ebus_alloc_bus_tag(sc, type)
394 1.8 mrg struct ebus_softc *sc;
395 1.8 mrg int type;
396 1.8 mrg {
397 1.8 mrg bus_space_tag_t bt;
398 1.8 mrg
399 1.8 mrg bt = (bus_space_tag_t)
400 1.8 mrg malloc(sizeof(struct sparc_bus_space_tag), M_DEVBUF, M_NOWAIT);
401 1.8 mrg if (bt == NULL)
402 1.8 mrg panic("could not allocate ebus bus tag");
403 1.8 mrg
404 1.42 martin memset(bt, 0, sizeof *bt);
405 1.8 mrg bt->cookie = sc;
406 1.23 eeh bt->parent = sc->sc_memtag;
407 1.8 mrg bt->type = type;
408 1.8 mrg bt->sparc_bus_map = _ebus_bus_map;
409 1.8 mrg bt->sparc_bus_mmap = ebus_bus_mmap;
410 1.8 mrg bt->sparc_intr_establish = ebus_intr_establish;
411 1.8 mrg return (bt);
412 1.8 mrg }
413 1.8 mrg
414 1.8 mrg static int
415 1.31 mrg _ebus_bus_map(t, ba, size, flags, va, hp)
416 1.8 mrg bus_space_tag_t t;
417 1.31 mrg bus_addr_t ba;
418 1.8 mrg bus_size_t size;
419 1.8 mrg int flags;
420 1.31 mrg vaddr_t va;
421 1.8 mrg bus_space_handle_t *hp;
422 1.8 mrg {
423 1.8 mrg struct ebus_softc *sc = t->cookie;
424 1.31 mrg paddr_t offset;
425 1.31 mrg u_int bar;
426 1.23 eeh int i, ss;
427 1.8 mrg
428 1.31 mrg bar = BUS_ADDR_IOSPACE(ba);
429 1.31 mrg offset = BUS_ADDR_PADDR(ba);
430 1.31 mrg
431 1.21 mrg DPRINTF(EDB_BUSMAP,
432 1.31 mrg ("\n_ebus_bus_map: bar %d offset %08x sz %x flags %x va %p\n",
433 1.31 mrg (int)bar, (u_int32_t)offset, (u_int32_t)size,
434 1.31 mrg flags, (void *)va));
435 1.31 mrg
436 1.8 mrg for (i = 0; i < sc->sc_nrange; i++) {
437 1.8 mrg bus_addr_t pciaddr;
438 1.8 mrg
439 1.31 mrg if (bar != sc->sc_range[i].child_hi)
440 1.8 mrg continue;
441 1.31 mrg if (offset < sc->sc_range[i].child_lo ||
442 1.31 mrg (offset + size) >
443 1.21 mrg (sc->sc_range[i].child_lo + sc->sc_range[i].size))
444 1.8 mrg continue;
445 1.8 mrg
446 1.23 eeh /* Isolate address space and find the right tag */
447 1.23 eeh ss = (sc->sc_range[i].phys_hi>>24)&3;
448 1.23 eeh switch (ss) {
449 1.23 eeh case 1: /* I/O space */
450 1.23 eeh t = sc->sc_iotag;
451 1.23 eeh break;
452 1.23 eeh case 2: /* Memory space */
453 1.23 eeh t = sc->sc_memtag;
454 1.23 eeh break;
455 1.23 eeh case 0: /* Config space */
456 1.23 eeh case 3: /* 64-bit Memory space */
457 1.23 eeh default: /* WTF? */
458 1.23 eeh /* We don't handle these */
459 1.23 eeh panic("_ebus_bus_map: illegal space %x", ss);
460 1.23 eeh break;
461 1.23 eeh }
462 1.8 mrg pciaddr = ((bus_addr_t)sc->sc_range[i].phys_mid << 32UL) |
463 1.8 mrg sc->sc_range[i].phys_lo;
464 1.31 mrg pciaddr += offset;
465 1.31 mrg
466 1.21 mrg DPRINTF(EDB_BUSMAP,
467 1.31 mrg ("_ebus_bus_map: mapping to PCI addr %x\n",
468 1.31 mrg (u_int32_t)pciaddr));
469 1.31 mrg
470 1.8 mrg /* pass it onto the psycho */
471 1.30 eeh return (bus_space_map(t, pciaddr, size, flags, hp));
472 1.8 mrg }
473 1.8 mrg DPRINTF(EDB_BUSMAP, (": FAILED\n"));
474 1.8 mrg return (EINVAL);
475 1.8 mrg }
476 1.8 mrg
477 1.27 eeh static paddr_t
478 1.27 eeh ebus_bus_mmap(t, paddr, off, prot, flags)
479 1.8 mrg bus_space_tag_t t;
480 1.8 mrg bus_addr_t paddr;
481 1.27 eeh off_t off;
482 1.27 eeh int prot;
483 1.8 mrg int flags;
484 1.8 mrg {
485 1.8 mrg bus_addr_t offset = paddr;
486 1.8 mrg struct ebus_softc *sc = t->cookie;
487 1.8 mrg int i;
488 1.8 mrg
489 1.8 mrg for (i = 0; i < sc->sc_nrange; i++) {
490 1.8 mrg bus_addr_t paddr = ((bus_addr_t)sc->sc_range[i].child_hi << 32) |
491 1.8 mrg sc->sc_range[i].child_lo;
492 1.8 mrg
493 1.8 mrg if (offset != paddr)
494 1.8 mrg continue;
495 1.8 mrg
496 1.21 mrg DPRINTF(EDB_BUSMAP, ("\n_ebus_bus_mmap: mapping paddr %qx\n",
497 1.21 mrg (unsigned long long)paddr));
498 1.27 eeh return (bus_space_mmap(sc->sc_memtag, paddr, off,
499 1.27 eeh prot, flags));
500 1.8 mrg }
501 1.8 mrg
502 1.8 mrg return (-1);
503 1.8 mrg }
504 1.8 mrg
505 1.8 mrg /*
506 1.29 mrg * install an interrupt handler for a ebus device
507 1.8 mrg */
508 1.8 mrg void *
509 1.36 pk ebus_intr_establish(t, pri, level, handler, arg, fastvec)
510 1.8 mrg bus_space_tag_t t;
511 1.15 pk int pri;
512 1.8 mrg int level;
513 1.8 mrg int (*handler) __P((void *));
514 1.8 mrg void *arg;
515 1.35 pk void (*fastvec) __P((void)); /* ignored */
516 1.8 mrg {
517 1.29 mrg
518 1.36 pk return (bus_intr_establish(t->parent, pri, level, handler, arg));
519 1.1 mrg }
520