]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/sparc64/ebus/ebus.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / sparc64 / ebus / ebus.c
1 /*-
2  * Copyright (c) 1999, 2000 Matthew R. Green
3  * Copyright (c) 2001 Thomas Moestl <tmm@FreeBSD.org>
4  * Copyright (c) 2009 by Marius Strobl <marius@FreeBSD.org>
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. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  *      from: NetBSD: ebus.c,v 1.26 2001/09/10 16:27:53 eeh Exp
31  */
32
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35
36 /*
37  * Driver for JBus to EBus and PCI to EBus bridges
38  */
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/bus.h>
43 #include <sys/kernel.h>
44 #include <sys/malloc.h>
45 #include <sys/module.h>
46
47 #include <sys/rman.h>
48
49 #include <dev/ofw/ofw_bus.h>
50 #include <dev/ofw/ofw_bus_subr.h>
51 #include <dev/ofw/openfirm.h>
52
53 #include <machine/bus.h>
54 #ifndef SUN4V
55 #include <machine/bus_common.h>
56 #endif
57 #include <machine/intr_machdep.h>
58 #include <machine/resource.h>
59
60 #include <dev/pci/pcireg.h>
61 #include <dev/pci/pcivar.h>
62
63 #include <sparc64/pci/ofw_pci.h>
64
65 /*
66  * The register, interrupt map and for the PCI variant also the ranges
67  * properties are identical to the ISA ones.
68  */
69 #include <sparc64/isa/ofw_isa.h>
70
71 struct ebus_nexus_ranges {
72         uint32_t        child_hi;
73         uint32_t        child_lo;
74         uint32_t        phys_hi;
75         uint32_t        phys_lo;
76         uint32_t        size;
77 };
78
79 struct ebus_devinfo {
80         struct ofw_bus_devinfo  edi_obdinfo;
81         struct resource_list    edi_rl;
82 };
83
84 struct ebus_rinfo {
85         int                     eri_rtype;
86         struct rman             eri_rman;
87         struct resource         *eri_res;
88 };
89
90 struct ebus_softc {
91         void                    *sc_range;
92         struct ebus_rinfo       *sc_rinfo;
93
94         u_int                   sc_flags;
95 #define EBUS_PCI                (1 << 0)
96
97         int                     sc_nrange;
98
99         struct ofw_bus_iinfo    sc_iinfo;
100
101 #ifndef SUN4V
102         uint32_t                sc_ign;
103 #endif
104 };
105
106 static device_probe_t ebus_nexus_probe;
107 static device_attach_t ebus_nexus_attach;
108 static device_probe_t ebus_pci_probe;
109 static device_attach_t ebus_pci_attach;
110 static bus_print_child_t ebus_print_child;
111 static bus_probe_nomatch_t ebus_probe_nomatch;
112 static bus_alloc_resource_t ebus_alloc_resource;
113 static bus_release_resource_t ebus_release_resource;
114 static bus_setup_intr_t ebus_setup_intr;
115 static bus_get_resource_list_t ebus_get_resource_list;
116 static ofw_bus_get_devinfo_t ebus_get_devinfo;
117
118 static int ebus_attach(device_t dev, struct ebus_softc *sc, phandle_t node);
119 static struct ebus_devinfo *ebus_setup_dinfo(device_t dev,
120     struct ebus_softc *sc, phandle_t node);
121 static void ebus_destroy_dinfo(struct ebus_devinfo *edi);
122 static int ebus_print_res(struct ebus_devinfo *edi);
123
124 static devclass_t ebus_devclass;
125
126 static device_method_t ebus_nexus_methods[] = {
127         /* Device interface */
128         DEVMETHOD(device_probe,         ebus_nexus_probe),
129         DEVMETHOD(device_attach,        ebus_nexus_attach),
130         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
131         DEVMETHOD(device_suspend,       bus_generic_suspend),
132         DEVMETHOD(device_resume,        bus_generic_resume),
133
134         /* Bus interface */
135         DEVMETHOD(bus_print_child,      ebus_print_child),
136         DEVMETHOD(bus_probe_nomatch,    ebus_probe_nomatch),
137         DEVMETHOD(bus_alloc_resource,   ebus_alloc_resource),
138         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
139         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
140         DEVMETHOD(bus_release_resource, ebus_release_resource),
141         DEVMETHOD(bus_setup_intr,       ebus_setup_intr),
142         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
143         DEVMETHOD(bus_get_resource,     bus_generic_rl_get_resource),
144         DEVMETHOD(bus_get_resource_list, ebus_get_resource_list),
145         DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str),
146
147         /* ofw_bus interface */
148         DEVMETHOD(ofw_bus_get_devinfo,  ebus_get_devinfo),
149         DEVMETHOD(ofw_bus_get_compat,   ofw_bus_gen_get_compat),
150         DEVMETHOD(ofw_bus_get_model,    ofw_bus_gen_get_model),
151         DEVMETHOD(ofw_bus_get_name,     ofw_bus_gen_get_name),
152         DEVMETHOD(ofw_bus_get_node,     ofw_bus_gen_get_node),
153         DEVMETHOD(ofw_bus_get_type,     ofw_bus_gen_get_type),
154
155         KOBJMETHOD_END
156 };
157
158 static driver_t ebus_nexus_driver = {
159         "ebus",
160         ebus_nexus_methods,
161         sizeof(struct ebus_softc),
162 };
163
164 /*
165  * NB: we rely on the interrupt controllers of the accompanying PCI-Express
166  * bridge to be registered as the nexus variant of the EBus bridges doesn't
167  * employ its own one.
168  */
169 EARLY_DRIVER_MODULE(ebus, nexus, ebus_nexus_driver, ebus_devclass, 0, 0,
170     BUS_PASS_BUS + 1);
171 MODULE_DEPEND(ebus, nexus, 1, 1, 1);
172
173 static device_method_t ebus_pci_methods[] = {
174         /* Device interface */
175         DEVMETHOD(device_probe,         ebus_pci_probe),
176         DEVMETHOD(device_attach,        ebus_pci_attach),
177         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
178         DEVMETHOD(device_suspend,       bus_generic_suspend),
179         DEVMETHOD(device_resume,        bus_generic_resume),
180
181         /* Bus interface */
182         DEVMETHOD(bus_print_child,      ebus_print_child),
183         DEVMETHOD(bus_probe_nomatch,    ebus_probe_nomatch),
184         DEVMETHOD(bus_alloc_resource,   ebus_alloc_resource),
185         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
186         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
187         DEVMETHOD(bus_release_resource, ebus_release_resource),
188         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
189         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
190         DEVMETHOD(bus_get_resource,     bus_generic_rl_get_resource),
191         DEVMETHOD(bus_get_resource_list, ebus_get_resource_list),
192         DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str),
193
194         /* ofw_bus interface */
195         DEVMETHOD(ofw_bus_get_devinfo,  ebus_get_devinfo),
196         DEVMETHOD(ofw_bus_get_compat,   ofw_bus_gen_get_compat),
197         DEVMETHOD(ofw_bus_get_model,    ofw_bus_gen_get_model),
198         DEVMETHOD(ofw_bus_get_name,     ofw_bus_gen_get_name),
199         DEVMETHOD(ofw_bus_get_node,     ofw_bus_gen_get_node),
200         DEVMETHOD(ofw_bus_get_type,     ofw_bus_gen_get_type),
201
202         KOBJMETHOD_END
203 };
204
205 static driver_t ebus_pci_driver = {
206         "ebus",
207         ebus_pci_methods,
208         sizeof(struct ebus_softc),
209 };
210
211 EARLY_DRIVER_MODULE(ebus, pci, ebus_pci_driver, ebus_devclass, 0, 0,
212     BUS_PASS_BUS);
213 MODULE_DEPEND(ebus, pci, 1, 1, 1);
214 MODULE_VERSION(ebus, 1);
215
216 static int
217 ebus_nexus_probe(device_t dev)
218 {
219         const char* compat;
220
221         compat = ofw_bus_get_compat(dev);
222         if (compat != NULL && strcmp(ofw_bus_get_name(dev), "ebus") == 0 &&
223             strcmp(compat, "jbus-ebus") == 0) {
224                 device_set_desc(dev, "JBus-EBus bridge");
225                 return (BUS_PROBE_GENERIC);
226         }
227         return (ENXIO);
228 }
229
230 static int
231 ebus_pci_probe(device_t dev)
232 {
233
234         if (pci_get_class(dev) != PCIC_BRIDGE ||
235             pci_get_vendor(dev) != 0x108e ||
236             strcmp(ofw_bus_get_name(dev), "ebus") != 0)
237                 return (ENXIO);
238
239         if (pci_get_device(dev) == 0x1000)
240                 device_set_desc(dev, "PCI-EBus2 bridge");
241         else if (pci_get_device(dev) == 0x1100)
242                 device_set_desc(dev, "PCI-EBus3 bridge");
243         else
244                 return (ENXIO);
245         return (BUS_PROBE_GENERIC);
246 }
247
248 static int
249 ebus_nexus_attach(device_t dev)
250 {
251         struct ebus_softc *sc;
252         phandle_t node;
253
254         sc = device_get_softc(dev);
255         node = ofw_bus_get_node(dev);
256
257 #ifndef SUN4V
258         if (OF_getprop(node, "portid", &sc->sc_ign,
259             sizeof(sc->sc_ign)) == -1) {
260                 device_printf(dev, "could not determine IGN");
261                 return (ENXIO);
262         }
263 #endif
264
265         sc->sc_nrange = OF_getprop_alloc(node, "ranges",
266             sizeof(struct ebus_nexus_ranges), &sc->sc_range);
267         if (sc->sc_nrange == -1) {
268                 printf("%s: could not get ranges property\n", __func__);
269                 return (ENXIO);
270         }
271         return (ebus_attach(dev, sc, node));
272 }
273
274 static int
275 ebus_pci_attach(device_t dev)
276 {
277         struct ebus_softc *sc;
278         struct ebus_rinfo *eri;
279         struct resource *res;
280         phandle_t node;
281         int i, rnum, rid;
282
283         sc = device_get_softc(dev);
284         sc->sc_flags |= EBUS_PCI;
285
286         pci_write_config(dev, PCIR_COMMAND,
287             pci_read_config(dev, PCIR_COMMAND, 2) | PCIM_CMD_SERRESPEN |
288             PCIM_CMD_PERRESPEN | PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN, 2);
289         pci_write_config(dev, PCIR_CACHELNSZ, 16 /* 64 bytes */, 1);
290         pci_write_config(dev, PCIR_LATTIMER, 64 /* 64 PCI cycles */, 1);
291
292         node = ofw_bus_get_node(dev);
293         sc->sc_nrange = OF_getprop_alloc(node, "ranges",
294             sizeof(struct isa_ranges), &sc->sc_range);
295         if (sc->sc_nrange == -1) {
296                 printf("%s: could not get ranges property\n", __func__);
297                 return (ENXIO);
298         }
299
300         sc->sc_rinfo = malloc(sizeof(*sc->sc_rinfo) * sc->sc_nrange, M_DEVBUF,
301             M_WAITOK | M_ZERO);
302
303         /* For every range, there must be a matching resource. */
304         for (rnum = 0; rnum < sc->sc_nrange; rnum++) {
305                 eri = &sc->sc_rinfo[rnum];
306                 eri->eri_rtype = ofw_isa_range_restype(
307                     &((struct isa_ranges *)sc->sc_range)[rnum]);
308                 rid = PCIR_BAR(rnum);
309                 res = bus_alloc_resource_any(dev, eri->eri_rtype, &rid,
310                     RF_ACTIVE);
311                 if (res == NULL) {
312                         printf("%s: failed to allocate range resource!\n",
313                             __func__);
314                         goto fail;
315                 }
316                 eri->eri_res = res;
317                 eri->eri_rman.rm_type = RMAN_ARRAY;
318                 eri->eri_rman.rm_descr = "EBus range";
319                 if (rman_init(&eri->eri_rman) != 0) {
320                         printf("%s: failed to initialize rman!", __func__);
321                         goto fail;
322                 }
323                 if (rman_manage_region(&eri->eri_rman, rman_get_start(res),
324                     rman_get_end(res)) != 0) {
325                         printf("%s: failed to register region!", __func__);
326                         rman_fini(&eri->eri_rman);
327                         goto fail;
328                 }
329         }
330         return (ebus_attach(dev, sc, node));
331
332  fail:
333         for (i = rnum; i >= 0; i--) {
334                 eri = &sc->sc_rinfo[i];
335                 if (i < rnum)
336                         rman_fini(&eri->eri_rman);
337                 if (eri->eri_res != 0) {
338                         bus_release_resource(dev, eri->eri_rtype,
339                             PCIR_BAR(rnum), eri->eri_res);
340                 }
341         }
342         free(sc->sc_rinfo, M_DEVBUF);
343         free(sc->sc_range, M_OFWPROP);
344         return (ENXIO);
345 }
346
347 static int
348 ebus_attach(device_t dev, struct ebus_softc *sc, phandle_t node)
349 {
350         struct ebus_devinfo *edi;
351         device_t cdev;
352
353         ofw_bus_setup_iinfo(node, &sc->sc_iinfo, sizeof(ofw_isa_intr_t));
354
355         /*
356          * Now attach our children.
357          */
358         for (node = OF_child(node); node > 0; node = OF_peer(node)) {
359                 if ((edi = ebus_setup_dinfo(dev, sc, node)) == NULL)
360                         continue;
361                 if ((cdev = device_add_child(dev, NULL, -1)) == NULL) {
362                         device_printf(dev, "<%s>: device_add_child failed\n",
363                             edi->edi_obdinfo.obd_name);
364                         ebus_destroy_dinfo(edi);
365                         continue;
366                 }
367                 device_set_ivars(cdev, edi);
368         }
369         return (bus_generic_attach(dev));
370 }
371
372 static int
373 ebus_print_child(device_t dev, device_t child)
374 {
375         int retval;
376
377         retval = bus_print_child_header(dev, child);
378         retval += ebus_print_res(device_get_ivars(child));
379         retval += bus_print_child_footer(dev, child);
380         return (retval);
381 }
382
383 static void
384 ebus_probe_nomatch(device_t dev, device_t child)
385 {
386
387         device_printf(dev, "<%s>", ofw_bus_get_name(child));
388         ebus_print_res(device_get_ivars(child));
389         printf(" (no driver attached)\n");
390 }
391
392 static struct resource *
393 ebus_alloc_resource(device_t bus, device_t child, int type, int *rid,
394     u_long start, u_long end, u_long count, u_int flags)
395 {
396         struct ebus_softc *sc;
397         struct resource_list *rl;
398         struct resource_list_entry *rle = NULL;
399         struct resource *res;
400         struct ebus_rinfo *ri;
401         struct ebus_nexus_ranges *enr;
402         bus_space_tag_t bt;
403         bus_space_handle_t bh;
404         uint64_t cend, cstart, offset;
405         int i, isdefault, passthrough, ridx, rv;
406
407         isdefault = (start == 0UL && end == ~0UL);
408         passthrough = (device_get_parent(child) != bus);
409         sc = device_get_softc(bus);
410         rl = BUS_GET_RESOURCE_LIST(bus, child);
411         switch (type) {
412         case SYS_RES_MEMORY:
413                 KASSERT(!(isdefault && passthrough),
414                     ("%s: passthrough of default allocation", __func__));
415                 if (!passthrough) {
416                         rle = resource_list_find(rl, type, *rid);
417                         if (rle == NULL)
418                                 return (NULL);
419                         KASSERT(rle->res == NULL,
420                             ("%s: resource entry is busy", __func__));
421                         if (isdefault) {
422                                 start = rle->start;
423                                 count = ulmax(count, rle->count);
424                                 end = ulmax(rle->end, start + count - 1);
425                         }
426                 }
427
428                 res = NULL;
429                 if ((sc->sc_flags & EBUS_PCI) != 0) {
430                         /*
431                          * Map EBus ranges to PCI ranges.  This may include
432                          * changing the allocation type.
433                          */
434                         (void)ofw_isa_range_map(sc->sc_range, sc->sc_nrange,
435                             &start, &end, &ridx);
436                         ri = &sc->sc_rinfo[ridx];
437                         res = rman_reserve_resource(&ri->eri_rman, start, end,
438                             count, flags, child);
439                         if (res == NULL)
440                                 return (NULL);
441                         rman_set_rid(res, *rid);
442                         bt = rman_get_bustag(ri->eri_res);
443                         rman_set_bustag(res, bt);
444                         rv = bus_space_subregion(bt,
445                             rman_get_bushandle(ri->eri_res),
446                             rman_get_start(res) - rman_get_start(ri->eri_res),
447                             count, &bh);
448                         if (rv != 0) {
449                                 rman_release_resource(res);
450                                 return (NULL);
451                         }
452                         rman_set_bushandle(res, bh);
453                 } else {
454                         /* Map EBus ranges to nexus ranges. */
455                         for (i = 0; i < sc->sc_nrange; i++) {
456                                 enr = &((struct ebus_nexus_ranges *)
457                                     sc->sc_range)[i];
458                                 cstart = (((uint64_t)enr->child_hi) << 32) |
459                                     enr->child_lo;
460                                 cend = cstart + enr->size - 1;
461                                 if (start >= cstart && end <= cend) {
462                                         offset =
463                                             (((uint64_t)enr->phys_hi) << 32) |
464                                             enr->phys_lo;
465                                         start += offset - cstart;
466                                         end += offset - cstart;
467                                         res = bus_generic_alloc_resource(bus,
468                                             child, type, rid, start, end,
469                                             count, flags);
470                                         break;
471                                 }
472                         }
473
474                 }
475                 if (!passthrough)
476                         rle->res = res;
477                 return (res);
478         case SYS_RES_IRQ:
479                 return (resource_list_alloc(rl, bus, child, type, rid, start,
480                     end, count, flags));
481         }
482         return (NULL);
483 }
484
485 static int
486 ebus_release_resource(device_t bus, device_t child, int type, int rid,
487     struct resource *res)
488 {
489         struct ebus_softc *sc;
490         struct resource_list *rl;
491         struct resource_list_entry *rle;
492         int passthrough, rv;
493
494         passthrough = (device_get_parent(child) != bus);
495         rl = BUS_GET_RESOURCE_LIST(bus, child);
496         switch (type) {
497         case SYS_RES_MEMORY:
498                 sc = device_get_softc(bus);
499                 if ((sc->sc_flags & EBUS_PCI) == 0)
500                         return (resource_list_release(rl, bus, child, type,
501                             rid, res));
502                 if ((rv = rman_release_resource(res)) != 0)
503                         return (rv);
504                 if (!passthrough) {
505                         rle = resource_list_find(rl, type, rid);
506                         KASSERT(rle != NULL,
507                             ("%s: resource entry not found!", __func__));
508                         KASSERT(rle->res != NULL,
509                            ("%s: resource entry is not busy", __func__));
510                         rle->res = NULL;
511                 }
512                 break;
513         case SYS_RES_IRQ:
514                 return (resource_list_release(rl, bus, child, type, rid, res));
515         default:
516                 panic("%s: unsupported resource type %d", __func__, type);
517         }
518         return (0);
519 }
520
521 static int
522 ebus_setup_intr(device_t dev, device_t child, struct resource *ires,
523     int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg,
524     void **cookiep)
525 {
526 #ifndef SUN4V
527         struct ebus_softc *sc;
528         u_long vec;
529
530         sc = device_get_softc(dev);
531         if ((sc->sc_flags & EBUS_PCI) == 0) {
532                 /*
533                  * Make sure the vector is fully specified.  This isn't
534                  * necessarily the case with the PCI variant.
535                  */
536                 vec = rman_get_start(ires);
537                 if (INTIGN(vec) != sc->sc_ign) {
538                         device_printf(dev,
539                             "invalid interrupt vector 0x%lx\n", vec);
540                         return (EINVAL);
541                 }
542
543                 /*
544                  * As we rely on the interrupt controllers of the
545                  * accompanying PCI-Express bridge ensure at least
546                  * something is registered for this vector.
547                  */
548                 if (intr_vectors[vec].iv_ic == NULL) {
549                         device_printf(dev,
550                             "invalid interrupt controller for vector 0x%lx\n",
551                             vec);
552                         return (EINVAL);
553                 }
554         }
555 #endif
556         return (bus_generic_setup_intr(dev, child, ires, flags, filt, intr,
557             arg, cookiep));
558 }
559
560 static struct resource_list *
561 ebus_get_resource_list(device_t dev, device_t child)
562 {
563         struct ebus_devinfo *edi;
564
565         edi = device_get_ivars(child);
566         return (&edi->edi_rl);
567 }
568
569 static const struct ofw_bus_devinfo *
570 ebus_get_devinfo(device_t bus, device_t dev)
571 {
572         struct ebus_devinfo *edi;
573
574         edi = device_get_ivars(dev);
575         return (&edi->edi_obdinfo);
576 }
577
578 static struct ebus_devinfo *
579 ebus_setup_dinfo(device_t dev, struct ebus_softc *sc, phandle_t node)
580 {
581         struct isa_regs reg, *regs;
582         ofw_isa_intr_t intr, *intrs;
583         struct ebus_devinfo *edi;
584         uint64_t start;
585         uint32_t rintr;
586         int i, nintr, nreg, rv;
587         uint8_t maskbuf[sizeof(reg) + sizeof(intr)];
588
589         edi = malloc(sizeof(*edi), M_DEVBUF, M_ZERO | M_WAITOK);
590         if (ofw_bus_gen_setup_devinfo(&edi->edi_obdinfo, node) != 0) {
591                 free(edi, M_DEVBUF);
592                 return (NULL);
593         }
594         resource_list_init(&edi->edi_rl);
595         nreg = OF_getprop_alloc(node, "reg", sizeof(*regs), (void **)&regs);
596         if (nreg == -1) {
597                 device_printf(dev, "<%s>: incomplete\n",
598                     edi->edi_obdinfo.obd_name);
599                 ebus_destroy_dinfo(edi);
600                 return (NULL);
601         }
602         for (i = 0; i < nreg; i++) {
603                 start = ISA_REG_PHYS(regs + i);
604                 (void)resource_list_add(&edi->edi_rl, SYS_RES_MEMORY, i,
605                     start, start + regs[i].size - 1, regs[i].size);
606         }
607         free(regs, M_OFWPROP);
608
609         nintr = OF_getprop_alloc(node, "interrupts",  sizeof(*intrs),
610             (void **)&intrs);
611         if (nintr == -1)
612                 return (edi);
613         for (i = 0; i < nintr; i++) {
614                 rv = 0;
615                 if ((sc->sc_flags & EBUS_PCI) != 0) {
616                         rintr = ofw_isa_route_intr(dev, node, &sc->sc_iinfo,
617                             intrs[i]);
618                 } else {
619                         intr = intrs[i];
620                         rv = ofw_bus_lookup_imap(node, &sc->sc_iinfo, &reg,
621                             sizeof(reg), &intr, sizeof(intr), &rintr,
622                             sizeof(rintr), maskbuf);
623 #ifndef SUN4V
624                         if (rv != 0)
625                                 rintr = INTMAP_VEC(sc->sc_ign, rintr);
626 #endif
627                 }
628                 if ((sc->sc_flags & EBUS_PCI) == 0 ? rv == 0 :
629                     rintr == PCI_INVALID_IRQ) {
630                         device_printf(dev,
631                             "<%s>: could not map EBus interrupt %d\n",
632                             edi->edi_obdinfo.obd_name, intrs[i]);
633                         continue;
634                 }
635                 (void)resource_list_add(&edi->edi_rl, SYS_RES_IRQ, i, rintr,
636                     rintr, 1);
637         }
638         free(intrs, M_OFWPROP);
639         return (edi);
640 }
641
642 static void
643 ebus_destroy_dinfo(struct ebus_devinfo *edi)
644 {
645
646         resource_list_free(&edi->edi_rl);
647         ofw_bus_gen_destroy_devinfo(&edi->edi_obdinfo);
648         free(edi, M_DEVBUF);
649 }
650
651 static int
652 ebus_print_res(struct ebus_devinfo *edi)
653 {
654         int retval;
655
656         retval = 0;
657         retval += resource_list_print_type(&edi->edi_rl, "addr", SYS_RES_MEMORY,
658             "%#lx");
659         retval += resource_list_print_type(&edi->edi_rl, "irq", SYS_RES_IRQ,
660             "%ld");
661         return (retval);
662 }