ofwbus.c revision 261351
15962Sgoetz/*-
211020Scoleenp * Copyright 1998 Massachusetts Institute of Technology
310049Sgoetz * Copyright 2001 by Thomas Moestl <tmm@FreeBSD.org>.
45962Sgoetz * Copyright 2006 by Marius Strobl <marius@FreeBSD.org>.
55962Sgoetz * All rights reserved.
65962Sgoetz *
75962Sgoetz * Permission to use, copy, modify, and distribute this software and
85962Sgoetz * its documentation for any purpose and without fee is hereby
95962Sgoetz * granted, provided that both the above copyright notice and this
105962Sgoetz * permission notice appear in all copies, that both the above
115962Sgoetz * copyright notice and this permission notice appear in all
125962Sgoetz * supporting documentation, and that the name of M.I.T. not be used
135962Sgoetz * in advertising or publicity pertaining to distribution of the
145962Sgoetz * software without specific, written prior permission.  M.I.T. makes
155962Sgoetz * no representations about the suitability of this software for any
165962Sgoetz * purpose.  It is provided "as is" without express or implied
175962Sgoetz * warranty.
185962Sgoetz *
195962Sgoetz * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
205962Sgoetz * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
215962Sgoetz * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
225962Sgoetz * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
235962Sgoetz * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
245962Sgoetz * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
255962Sgoetz * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
265962Sgoetz * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
275962Sgoetz * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
285962Sgoetz * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
295962Sgoetz * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
305962Sgoetz * SUCH DAMAGE.
315962Sgoetz *
325962Sgoetz * 	from: FreeBSD: src/sys/i386/i386/nexus.c,v 1.43 2001/02/09
335962Sgoetz */
345962Sgoetz
355962Sgoetz#include <sys/cdefs.h>
365962Sgoetz__FBSDID("$FreeBSD: head/sys/dev/ofw/ofw_nexus.c 261351 2014-02-01 17:17:35Z nwhitehorn $");
375962Sgoetz
385962Sgoetz#include <sys/param.h>
395962Sgoetz#include <sys/systm.h>
405962Sgoetz#include <sys/bus.h>
415962Sgoetz#include <sys/kernel.h>
425962Sgoetz#include <sys/malloc.h>
435962Sgoetz#include <sys/module.h>
445962Sgoetz#include <sys/pcpu.h>
455962Sgoetz#include <sys/rman.h>
465962Sgoetz
475962Sgoetz#include <vm/vm.h>
486108Sgoetz#include <vm/pmap.h>
495962Sgoetz
505962Sgoetz#include <dev/ofw/ofw_bus.h>
515962Sgoetz#include <dev/ofw/ofw_bus_subr.h>
525962Sgoetz#include <dev/ofw/ofw_nexus.h>
535962Sgoetz#include <dev/ofw/openfirm.h>
545962Sgoetz
555962Sgoetz#include <machine/bus.h>
565962Sgoetz#include <machine/resource.h>
575962Sgoetz
585962Sgoetz/*
595962Sgoetz * The nexus (which is a pseudo-bus actually) iterates over the nodes that
605962Sgoetz * hang from the Open Firmware root node and adds them as devices to this bus
615962Sgoetz * (except some special nodes which are excluded) so that drivers can be
625962Sgoetz * attached to them.
635962Sgoetz *
645962Sgoetz * Additionally, interrupt setup/teardown and some resource management are
655962Sgoetz * done at this level.
665962Sgoetz *
675962Sgoetz */
685962Sgoetz
695962Sgoetzstruct nexus_devinfo {
705962Sgoetz	struct ofw_bus_devinfo	ndi_obdinfo;
715962Sgoetz	struct resource_list	ndi_rl;
725962Sgoetz};
735962Sgoetz
745962Sgoetzstatic device_probe_t nexus_probe;
756108Sgoetzstatic device_attach_t nexus_attach;
765962Sgoetzstatic bus_print_child_t nexus_print_child;
775962Sgoetzstatic bus_add_child_t nexus_add_child;
785962Sgoetzstatic bus_probe_nomatch_t nexus_probe_nomatch;
795962Sgoetzstatic bus_alloc_resource_t nexus_alloc_resource;
805962Sgoetzstatic bus_adjust_resource_t nexus_adjust_resource;
815962Sgoetzstatic bus_release_resource_t nexus_release_resource;
825962Sgoetzstatic bus_get_resource_list_t nexus_get_resource_list;
835962Sgoetzstatic ofw_bus_get_devinfo_t nexus_get_devinfo;
845962Sgoetz
855962Sgoetzstatic int nexus_inlist(const char *, const char *const *);
865962Sgoetzstatic struct nexus_devinfo * nexus_setup_dinfo(device_t, phandle_t);
875962Sgoetzstatic void nexus_destroy_dinfo(struct nexus_devinfo *);
885962Sgoetzstatic int nexus_print_res(struct nexus_devinfo *);
895962Sgoetz
905962Sgoetzstatic device_method_t nexus_methods[] = {
915962Sgoetz	/* Device interface */
925962Sgoetz	DEVMETHOD(device_probe,		nexus_probe),
936108Sgoetz	DEVMETHOD(device_attach,	nexus_attach),
946108Sgoetz	DEVMETHOD(device_detach,	bus_generic_detach),
955962Sgoetz	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
965962Sgoetz	DEVMETHOD(device_suspend,	bus_generic_suspend),
975962Sgoetz	DEVMETHOD(device_resume,	bus_generic_resume),
986108Sgoetz
995962Sgoetz	/* Bus interface */
1005962Sgoetz	DEVMETHOD(bus_print_child,	nexus_print_child),
1016108Sgoetz	DEVMETHOD(bus_probe_nomatch,	nexus_probe_nomatch),
1025962Sgoetz	DEVMETHOD(bus_read_ivar,	bus_generic_read_ivar),
1035962Sgoetz	DEVMETHOD(bus_write_ivar,	bus_generic_write_ivar),
1045962Sgoetz	DEVMETHOD(bus_add_child,	nexus_add_child),
1055962Sgoetz	DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str),
1065962Sgoetz	DEVMETHOD(bus_alloc_resource,	nexus_alloc_resource),
1075962Sgoetz	DEVMETHOD(bus_adjust_resource,	nexus_adjust_resource),
1086108Sgoetz	DEVMETHOD(bus_release_resource,	nexus_release_resource),
1095962Sgoetz	DEVMETHOD(bus_set_resource,	bus_generic_rl_set_resource),
1105962Sgoetz	DEVMETHOD(bus_get_resource,	bus_generic_rl_get_resource),
1116108Sgoetz	DEVMETHOD(bus_get_resource_list, nexus_get_resource_list),
1125962Sgoetz
1135962Sgoetz	/* ofw_bus interface */
1145962Sgoetz	DEVMETHOD(ofw_bus_get_devinfo,	nexus_get_devinfo),
1155962Sgoetz	DEVMETHOD(ofw_bus_get_compat,	ofw_bus_gen_get_compat),
1165962Sgoetz	DEVMETHOD(ofw_bus_get_model,	ofw_bus_gen_get_model),
1175962Sgoetz	DEVMETHOD(ofw_bus_get_name,	ofw_bus_gen_get_name),
1185962Sgoetz	DEVMETHOD(ofw_bus_get_node,	ofw_bus_gen_get_node),
1195962Sgoetz	DEVMETHOD(ofw_bus_get_type,	ofw_bus_gen_get_type),
1205962Sgoetz
1215962Sgoetz	DEVMETHOD_END
1225962Sgoetz};
1235962Sgoetz
1246108SgoetzDEFINE_CLASS_0(ofw_nexus, ofw_nexus_driver, nexus_methods,
1255962Sgoetz    sizeof(struct ofw_nexus_softc));
1265962SgoetzMODULE_VERSION(ofw_nexus, 1);
1275962Sgoetz
1286108Sgoetzstatic const char *const nexus_excl_name[] = {
1295962Sgoetz	"FJSV,system",
1306108Sgoetz	"aliases",
1315962Sgoetz	"associations",
1325962Sgoetz	"chosen",
1335962Sgoetz	"cmp",
1345962Sgoetz	"counter-timer",	/* No separate device; handled by psycho/sbus */
1355962Sgoetz	"failsafe",
1365962Sgoetz	"memory",
1375962Sgoetz	"openprom",
1386108Sgoetz	"options",
1395962Sgoetz	"packages",
1405962Sgoetz	"physical-memory",
1416108Sgoetz	"rsc",
1426108Sgoetz	"sgcn",
1435962Sgoetz	"todsg",
1445962Sgoetz	"virtual-memory",
1455962Sgoetz	NULL
1465962Sgoetz};
1475962Sgoetz
1485962Sgoetzstatic const char *const nexus_excl_type[] = {
1495962Sgoetz	"core",
1505962Sgoetz	"cpu",
1515962Sgoetz	NULL
1525962Sgoetz};
1535962Sgoetz
1545962Sgoetzstatic int
1555962Sgoetznexus_inlist(const char *name, const char *const *list)
1565962Sgoetz{
1575962Sgoetz	int i;
1585962Sgoetz
1595962Sgoetz	if (name == NULL)
1605962Sgoetz		return (0);
1615962Sgoetz	for (i = 0; list[i] != NULL; i++)
1625962Sgoetz		if (strcmp(name, list[i]) == 0)
1635962Sgoetz			return (1);
1645962Sgoetz	return (0);
1655962Sgoetz}
1665962Sgoetz
1675962Sgoetz#define	NEXUS_EXCLUDED(name, type)					\
1685962Sgoetz	(nexus_inlist((name), nexus_excl_name) ||			\
1695962Sgoetz	((type) != NULL && nexus_inlist((type), nexus_excl_type)))
1705962Sgoetz
1715962Sgoetzstatic int
1725962Sgoetznexus_probe(device_t dev)
1735962Sgoetz{
1745962Sgoetz
1755962Sgoetz	/* Nexus does always match. */
1765962Sgoetz	device_set_desc(dev, "Open Firmware Nexus device");
1775962Sgoetz	return (0);
1785962Sgoetz}
1795962Sgoetz
1805962Sgoetzstatic int
1815962Sgoetznexus_attach(device_t dev)
1825962Sgoetz{
1835962Sgoetz	struct nexus_devinfo *ndi;
1845962Sgoetz	struct ofw_nexus_softc *sc;
1855962Sgoetz	device_t cdev;
1865962Sgoetz	phandle_t node;
1875962Sgoetz
1885962Sgoetz	sc = device_get_softc(dev);
1895962Sgoetz
1905962Sgoetz	node = OF_peer(0);
1915962Sgoetz
1925962Sgoetz	sc->sc_intr_rman.rm_type = RMAN_ARRAY;
1935962Sgoetz	sc->sc_intr_rman.rm_descr = "Interrupts";
1945962Sgoetz	sc->sc_mem_rman.rm_type = RMAN_ARRAY;
1959832Sgoetz	sc->sc_mem_rman.rm_descr = "Device Memory";
1969832Sgoetz	if (rman_init(&sc->sc_intr_rman) != 0 ||
1979832Sgoetz	    rman_init(&sc->sc_mem_rman) != 0 ||
1989832Sgoetz	    rman_manage_region(&sc->sc_intr_rman, 0, ~0) != 0 ||
1999832Sgoetz	    rman_manage_region(&sc->sc_mem_rman, 0, BUS_SPACE_MAXADDR) != 0)
2006118Sgoetz		panic("%s: failed to set up rmans.", __func__);
2019832Sgoetz
2029832Sgoetz	/*
2039832Sgoetz	 * Allow devices to identify.
2049832Sgoetz	 */
2059832Sgoetz	bus_generic_probe(dev);
2069832Sgoetz
2079832Sgoetz	/*
2089832Sgoetz	 * If no Open Firmware, bail early
2099832Sgoetz	 */
2106118Sgoetz	if (node == -1)
2119832Sgoetz		return (bus_generic_attach(dev));
2126118Sgoetz
2136118Sgoetz	/*
2146118Sgoetz	 * Some important numbers
2156118Sgoetz	 */
2166118Sgoetz	sc->acells = 2;
2179832Sgoetz	OF_getencprop(node, "#address-cells", &sc->acells, sizeof(sc->acells));
2186118Sgoetz	sc->scells = 1;
2196118Sgoetz	OF_getencprop(node, "#size-cells", &sc->scells, sizeof(sc->scells));
2206118Sgoetz
2216118Sgoetz	/*
2226118Sgoetz	 * Now walk the OFW tree and attach top-level devices.
2236118Sgoetz	 */
2246118Sgoetz	for (node = OF_child(node); node > 0; node = OF_peer(node)) {
2256118Sgoetz		if ((ndi = nexus_setup_dinfo(dev, node)) == NULL)
2266118Sgoetz			continue;
2279832Sgoetz		cdev = device_add_child(dev, NULL, -1);
2289832Sgoetz		if (cdev == NULL) {
2296118Sgoetz			device_printf(dev, "<%s>: device_add_child failed\n",
2309832Sgoetz			    ndi->ndi_obdinfo.obd_name);
2319832Sgoetz			nexus_destroy_dinfo(ndi);
2329832Sgoetz			continue;
2339832Sgoetz		}
2349832Sgoetz		device_set_ivars(cdev, ndi);
2359832Sgoetz	}
2369832Sgoetz	return (bus_generic_attach(dev));
2376118Sgoetz}
2386118Sgoetz
2396118Sgoetzstatic device_t
2406118Sgoetznexus_add_child(device_t dev, u_int order, const char *name, int unit)
2416118Sgoetz{
2426118Sgoetz	device_t cdev;
2436118Sgoetz	struct nexus_devinfo *ndi;
2446118Sgoetz
2456118Sgoetz	cdev = device_add_child_ordered(dev, order, name, unit);
2466118Sgoetz	if (cdev == NULL)
2476118Sgoetz		return (NULL);
2486118Sgoetz
2496118Sgoetz	ndi = malloc(sizeof(*ndi), M_DEVBUF, M_WAITOK | M_ZERO);
2506118Sgoetz	ndi->ndi_obdinfo.obd_node = -1;
2516118Sgoetz	resource_list_init(&ndi->ndi_rl);
2526118Sgoetz	device_set_ivars(cdev, ndi);
2536118Sgoetz
2546118Sgoetz	return (cdev);
2556118Sgoetz}
2566118Sgoetz
2576118Sgoetzstatic int
2586118Sgoetznexus_print_child(device_t bus, device_t child)
2596118Sgoetz{
26012259Smdoerr	int rv;
2616118Sgoetz
2626118Sgoetz	rv = bus_print_child_header(bus, child);
26311020Scoleenp	rv += nexus_print_res(device_get_ivars(child));
2646118Sgoetz	rv += bus_print_child_footer(bus, child);
2656118Sgoetz	return (rv);
2666118Sgoetz}
2676118Sgoetz
2686118Sgoetzstatic void
2696118Sgoetznexus_probe_nomatch(device_t bus, device_t child)
2706118Sgoetz{
2716118Sgoetz	const char *name, *type;
2726118Sgoetz
2736118Sgoetz	if (!bootverbose)
2746118Sgoetz		return;
2756118Sgoetz
2766118Sgoetz	name = ofw_bus_get_name(child);
2776118Sgoetz	type = ofw_bus_get_type(child);
2786118Sgoetz
2796118Sgoetz	device_printf(bus, "<%s>",
2806118Sgoetz	    name != NULL ? name : "unknown");
2816118Sgoetz	nexus_print_res(device_get_ivars(child));
2826118Sgoetz	printf(" type %s (no driver attached)\n",
2836118Sgoetz	    type != NULL ? type : "unknown");
2846118Sgoetz}
2855962Sgoetz
2865962Sgoetzstatic struct resource *
2875962Sgoetznexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
2885962Sgoetz    u_long start, u_long end, u_long count, u_int flags)
2895962Sgoetz{
2905962Sgoetz	struct ofw_nexus_softc *sc;
2915962Sgoetz	struct rman *rm;
2925962Sgoetz	struct resource *rv;
2935962Sgoetz	struct resource_list_entry *rle;
2945962Sgoetz	int isdefault, passthrough;
2955962Sgoetz
2965962Sgoetz	isdefault = (start == 0UL && end == ~0UL);
2975962Sgoetz	passthrough = (device_get_parent(child) != bus);
2985962Sgoetz	sc = device_get_softc(bus);
2995962Sgoetz	rle = NULL;
3005962Sgoetz
3015962Sgoetz	if (!passthrough && isdefault) {
3025962Sgoetz		rle = resource_list_find(BUS_GET_RESOURCE_LIST(bus, child),
3035962Sgoetz		    type, *rid);
3045962Sgoetz		if (rle == NULL)
3055962Sgoetz			return (NULL);
3065962Sgoetz		if (rle->res != NULL)
3075962Sgoetz			panic("%s: resource entry is busy", __func__);
3085962Sgoetz		start = rle->start;
3095962Sgoetz		count = ulmax(count, rle->count);
3105962Sgoetz		end = ulmax(rle->end, start + count - 1);
3115962Sgoetz	}
3125962Sgoetz
3135962Sgoetz	switch (type) {
3145962Sgoetz	case SYS_RES_IRQ:
3155962Sgoetz		rm = &sc->sc_intr_rman;
3165962Sgoetz		break;
3175962Sgoetz	case SYS_RES_MEMORY:
3185962Sgoetz		rm = &sc->sc_mem_rman;
3195962Sgoetz		break;
3205962Sgoetz	default:
3215962Sgoetz		return (NULL);
3225962Sgoetz	}
3235962Sgoetz
3245962Sgoetz	rv = rman_reserve_resource(rm, start, end, count, flags & ~RF_ACTIVE,
3255962Sgoetz	    child);
3265962Sgoetz	if (rv == NULL)
3275962Sgoetz		return (NULL);
3285962Sgoetz	rman_set_rid(rv, *rid);
3295962Sgoetz
3305962Sgoetz	if ((flags & RF_ACTIVE) != 0 && bus_activate_resource(child, type,
3315962Sgoetz	    *rid, rv) != 0) {
3325962Sgoetz		rman_release_resource(rv);
3335962Sgoetz		return (NULL);
3345962Sgoetz	}
3355962Sgoetz
3365962Sgoetz	if (!passthrough && rle != NULL) {
3375962Sgoetz		rle->res = rv;
3385962Sgoetz		rle->start = rman_get_start(rv);
3395962Sgoetz		rle->end = rman_get_end(rv);
3405962Sgoetz		rle->count = rle->end - rle->start + 1;
3415962Sgoetz	}
3425962Sgoetz
3435962Sgoetz	return (rv);
3445962Sgoetz}
3455962Sgoetz
3465962Sgoetzstatic int
3475962Sgoetznexus_adjust_resource(device_t bus, device_t child __unused, int type,
3485962Sgoetz    struct resource *r, u_long start, u_long end)
3495962Sgoetz{
3505962Sgoetz	struct ofw_nexus_softc *sc;
3515962Sgoetz	struct rman *rm;
3525962Sgoetz	device_t nexus;
3535962Sgoetz
3545962Sgoetz	nexus = bus;
3555962Sgoetz	while (strcmp(device_get_name(device_get_parent(nexus)), "root") != 0)
3565962Sgoetz		nexus = device_get_parent(nexus);
3575962Sgoetz	sc = device_get_softc(nexus);
3585962Sgoetz	switch (type) {
3595962Sgoetz	case SYS_RES_IRQ:
3605962Sgoetz		rm = &sc->sc_intr_rman;
3615962Sgoetz		break;
3625962Sgoetz	case SYS_RES_MEMORY:
3635962Sgoetz		rm = &sc->sc_mem_rman;
3645962Sgoetz		break;
3655962Sgoetz	default:
3665962Sgoetz		return (EINVAL);
3675962Sgoetz	}
3685962Sgoetz	if (rm == NULL)
3695962Sgoetz		return (ENXIO);
3705962Sgoetz	if (rman_is_region_manager(r, rm) == 0)
3715962Sgoetz		return (EINVAL);
3725962Sgoetz	return (rman_adjust_resource(r, start, end));
3735962Sgoetz}
3745962Sgoetz
3755962Sgoetzstatic int
3765962Sgoetznexus_release_resource(device_t bus __unused, device_t child, int type,
3775962Sgoetz    int rid, struct resource *r)
3785962Sgoetz{
3795962Sgoetz	int error;
3805962Sgoetz
3816108Sgoetz	if ((rman_get_flags(r) & RF_ACTIVE) != 0) {
3826108Sgoetz		error = bus_deactivate_resource(child, type, rid, r);
3835962Sgoetz		if (error)
3845962Sgoetz			return (error);
3855962Sgoetz	}
3865962Sgoetz	return (rman_release_resource(r));
3875962Sgoetz}
3885962Sgoetz
3895962Sgoetzstatic struct resource_list *
3905962Sgoetznexus_get_resource_list(device_t bus __unused, device_t child)
3915962Sgoetz{
3925962Sgoetz	struct nexus_devinfo *ndi;
3935962Sgoetz
3945962Sgoetz	ndi = device_get_ivars(child);
3955962Sgoetz	return (&ndi->ndi_rl);
3965962Sgoetz}
3975962Sgoetz
3985962Sgoetzstatic const struct ofw_bus_devinfo *
3995962Sgoetznexus_get_devinfo(device_t bus __unused, device_t child)
4005962Sgoetz{
4015962Sgoetz	struct nexus_devinfo *ndi;
4025962Sgoetz
4035962Sgoetz	ndi = device_get_ivars(child);
4046118Sgoetz	return (&ndi->ndi_obdinfo);
4056118Sgoetz}
4066118Sgoetz
4076118Sgoetzstatic struct nexus_devinfo *
4086118Sgoetznexus_setup_dinfo(device_t dev, phandle_t node)
4096118Sgoetz{
4106118Sgoetz	struct ofw_nexus_softc *sc;
4115962Sgoetz	struct nexus_devinfo *ndi;
4125962Sgoetz	uint32_t *reg, *intr, icells;
4135962Sgoetz	uint64_t phys, size;
4145962Sgoetz	phandle_t iparent;
4155962Sgoetz	int i, j;
4165962Sgoetz	int nintr;
4175962Sgoetz	int nreg;
4185962Sgoetz
4195962Sgoetz	sc = device_get_softc(dev);
4205962Sgoetz
4215962Sgoetz	ndi = malloc(sizeof(*ndi), M_DEVBUF, M_WAITOK | M_ZERO);
4225962Sgoetz	if (ofw_bus_gen_setup_devinfo(&ndi->ndi_obdinfo, node) != 0) {
4235962Sgoetz		free(ndi, M_DEVBUF);
4245962Sgoetz		return (NULL);
4255962Sgoetz	}
4265962Sgoetz	if (NEXUS_EXCLUDED(ndi->ndi_obdinfo.obd_name,
4275962Sgoetz	    ndi->ndi_obdinfo.obd_type)) {
4285962Sgoetz		ofw_bus_gen_destroy_devinfo(&ndi->ndi_obdinfo);
4295962Sgoetz		free(ndi, M_DEVBUF);
4305962Sgoetz		return (NULL);
4315962Sgoetz	}
4325962Sgoetz
4335962Sgoetz	resource_list_init(&ndi->ndi_rl);
4345962Sgoetz	nreg = OF_getencprop_alloc(node, "reg", sizeof(*reg), (void **)&reg);
435	if (nreg == -1)
436		nreg = 0;
437	if (nreg % (sc->acells + sc->scells) != 0) {
438		if (bootverbose)
439			device_printf(dev, "Malformed reg property on <%s>\n",
440			    ndi->ndi_obdinfo.obd_name);
441		nreg = 0;
442	}
443
444	for (i = 0; i < nreg; i += sc->acells + sc->scells) {
445		phys = size = 0;
446		for (j = 0; j < sc->acells; j++) {
447			phys <<= 32;
448			phys |= reg[i + j];
449		}
450		for (j = 0; j < sc->scells; j++) {
451			size <<= 32;
452			size |= reg[i + sc->acells + j];
453		}
454		/* Skip the dummy reg property of glue devices like ssm(4). */
455		if (size != 0)
456			resource_list_add(&ndi->ndi_rl, SYS_RES_MEMORY, i,
457			    phys, phys + size - 1, size);
458	}
459	free(reg, M_OFWPROP);
460
461	nintr = OF_getencprop_alloc(node, "interrupts",  sizeof(*intr),
462	    (void **)&intr);
463	if (nintr > 0) {
464		iparent = 0;
465		OF_searchencprop(node, "interrupt-parent", &iparent,
466		    sizeof(iparent));
467		OF_searchencprop(OF_xref_phandle(iparent), "#interrupt-cells",
468		    &icells, sizeof(icells));
469		for (i = 0; i < nintr; i+= icells) {
470			intr[i] = ofw_bus_map_intr(dev, iparent, icells,
471			    &intr[i]);
472			resource_list_add(&ndi->ndi_rl, SYS_RES_IRQ, i, intr[i],
473			    intr[i], 1);
474		}
475		free(intr, M_OFWPROP);
476	}
477
478	return (ndi);
479}
480
481static void
482nexus_destroy_dinfo(struct nexus_devinfo *ndi)
483{
484
485	resource_list_free(&ndi->ndi_rl);
486	ofw_bus_gen_destroy_devinfo(&ndi->ndi_obdinfo);
487	free(ndi, M_DEVBUF);
488}
489
490static int
491nexus_print_res(struct nexus_devinfo *ndi)
492{
493	int rv;
494
495	rv = 0;
496	rv += resource_list_print_type(&ndi->ndi_rl, "mem", SYS_RES_MEMORY,
497	    "%#lx");
498	rv += resource_list_print_type(&ndi->ndi_rl, "irq", SYS_RES_IRQ,
499	    "%ld");
500	return (rv);
501}
502
503