Example #1
0
static int
nexus_attach(device_t dev)
{
    struct nexus_devinfo *ndi;
    struct nexus_softc *sc;
    device_t cdev;
    phandle_t node;

    if (strcmp(device_get_name(device_get_parent(dev)), "root") == 0) {
        node = OF_peer(0);
        if (node == -1)
            panic("%s: OF_peer failed.", __func__);

        sc = device_get_softc(dev);
        sc->sc_intr_rman.rm_type = RMAN_ARRAY;
        sc->sc_intr_rman.rm_descr = "Interrupts";
        sc->sc_mem_rman.rm_type = RMAN_ARRAY;
        sc->sc_mem_rman.rm_descr = "Device Memory";
        if (rman_init(&sc->sc_intr_rman) != 0 ||
                rman_init(&sc->sc_mem_rman) != 0 ||
                rman_manage_region(&sc->sc_intr_rman, 0,
                                   IV_MAX - 1) != 0 ||
                rman_manage_region(&sc->sc_mem_rman, 0ULL, ~0ULL) != 0)
            panic("%s: failed to set up rmans.", __func__);
    } else
        node = ofw_bus_get_node(dev);

    /*
     * Allow devices to identify.
     */
    bus_generic_probe(dev);

    /*
     * Now walk the OFW tree and attach top-level devices.
     */
    for (node = OF_child(node); node > 0; node = OF_peer(node)) {
        if ((ndi = nexus_setup_dinfo(dev, node)) == NULL)
            continue;
        cdev = device_add_child(dev, NULL, -1);
        if (cdev == NULL) {
            device_printf(dev, "<%s>: device_add_child failed\n",
                          ndi->ndi_obdinfo.obd_name);
            nexus_destroy_dinfo(ndi);
            continue;
        }
        device_set_ivars(cdev, ndi);
    }
    return (bus_generic_attach(dev));
}
Example #2
0
static int
nexus_attach(device_t dev)
{
	struct nexus_devinfo *ndi;
	struct nexus_softc *sc;
	device_t cdev;
	phandle_t node;

	sc = device_get_softc(dev);

	if (strcmp(device_get_name(device_get_parent(dev)), "root") == 0) {
		node = OF_peer(0);

		sc->sc_intr_rman.rm_type = RMAN_ARRAY;
		sc->sc_intr_rman.rm_descr = "Interrupts";
		sc->sc_mem_rman.rm_type = RMAN_ARRAY;
		sc->sc_mem_rman.rm_descr = "Device Memory";
		if (rman_init(&sc->sc_intr_rman) != 0 ||
		    rman_init(&sc->sc_mem_rman) != 0 ||
		    rman_manage_region(&sc->sc_intr_rman, 0, ~0) != 0 ||
		    rman_manage_region(&sc->sc_mem_rman, 0, BUS_SPACE_MAXADDR)
		     != 0)
			panic("%s: failed to set up rmans.", __func__);
	} else
		node = ofw_bus_get_node(dev);

	/*
	 * Allow devices to identify.
	 */
	bus_generic_probe(dev);

	/*
	 * If no Open Firmware, bail early
	 */
	if (node == -1)
		return (bus_generic_attach(dev));

	/*
	 * Some important numbers
	 */
	sc->acells = 2;
	OF_getprop(node, "#address-cells", &sc->acells, sizeof(sc->acells));
	sc->scells = 1;
	OF_getprop(node, "#size-cells", &sc->scells, sizeof(sc->scells));

	/*
	 * Now walk the OFW tree and attach top-level devices.
	 */
	for (node = OF_child(node); node > 0; node = OF_peer(node)) {
		if ((ndi = nexus_setup_dinfo(dev, node)) == NULL)
			continue;
		cdev = device_add_child(dev, NULL, -1);
		if (cdev == NULL) {
			device_printf(dev, "<%s>: device_add_child failed\n",
			    ndi->ndi_obdinfo.obd_name);
			nexus_destroy_dinfo(ndi);
			continue;
		}
		device_set_ivars(cdev, ndi);
	}
	return (bus_generic_attach(dev));
}