FreeBSD/sys/dev/bhnd/bhndb/bhndb.c
/**
 * Helper function that must be called by subclass bhndb(4) drivers
 * when implementing DEVICE_ATTACH() before calling any bhnd(4) or bhndb(4)
 * APIs on the bridge device.
 * 
 * @param dev The bridge device to attach.
 * @param bridge_devclass The device class of the bridging core. This is used
 * to automatically detect the bridge core, and to disable additional bridge
 * cores (e.g. PCMCIA on a PCIe device).
 */
Helper function that must be called by subclass bhndb(4) drivers
when implementing DEVICE_ATTACH() before calling any bhnd(4) or bhndb(4)
APIs on the bridge device.

@param dev The bridge device to attach.
@param bridge_devclass The device class of the bridging core. This is used
to automatically detect the bridge core, and to disable additional bridge
cores .
Helper function that must be called by subclass bhndb ( 4 ) drivers when implementing DEVICE_ATTACH () before calling any bhnd ( 4 ) or bhndb ( 4 ) APIs on the bridge device . @param dev The bridge device to attach . @param bridge_devclass The device class of the bridging core . This is used to automatically detect the bridge core and to disable additional bridge cores .
int
bhndb_attach(device_t dev, bhnd_devclass_t bridge_devclass)
{
	struct bhndb_devinfo		*dinfo;
	struct bhndb_softc		*sc;
	const struct bhndb_hwcfg	*cfg;
	int				 error;
	sc = device_get_softc(dev);
	sc->dev = dev;
	sc->parent_dev = device_get_parent(dev);
	sc->bridge_class = bridge_devclass;
	BHNDB_LOCK_INIT(sc);
	cfg = BHNDB_BUS_GET_GENERIC_HWCFG(sc->parent_dev, sc->dev);
	if ((error = bhndb_read_chipid(sc, cfg, &sc->chipid)))
		return (error);
	sc->bus_res = bhndb_alloc_resources(dev, sc->parent_dev, cfg);
	if (sc->bus_res == NULL) {
		return (ENXIO);
	}
	sc->bus_dev = BUS_ADD_CHILD(dev, 0, "bhnd", -1);
	if (sc->bus_dev == NULL) {
		error = ENXIO;
		goto failed;
	}
	dinfo = device_get_ivars(sc->bus_dev);
	dinfo->addrspace = BHNDB_ADDRSPACE_BRIDGED;
	return (bus_generic_attach(dev));
failed:
	BHNDB_LOCK_DESTROY(sc);
	if (sc->bus_res != NULL)
		bhndb_free_resources(sc->bus_res);
	return (error);
}
int bhndb_attach ( device_t dev , bhnd_devclass_t bridge_devclass ) { struct bhndb_devinfo * dinfo ; struct bhndb_softc * sc ; const struct bhndb_hwcfg * cfg ; int error ; sc = device_get_softc ( dev ) ; sc -> dev = dev ; sc -> parent_dev = device_get_parent ( dev ) ; sc -> bridge_class = bridge_devclass ; BHNDB_LOCK_INIT ( sc ) ; cfg = BHNDB_BUS_GET_GENERIC_HWCFG ( sc -> parent_dev , sc -> dev ) ; if ( ( error = bhndb_read_chipid ( sc , cfg , & sc -> chipid ) ) ) return ( error ) ; sc -> bus_res = bhndb_alloc_resources ( dev , sc -> parent_dev , cfg ) ; if ( sc -> bus_res == NULL ) { return ( ENXIO ) ; } sc -> bus_dev = BUS_ADD_CHILD ( dev , 0 , " " , -1 ) ; if ( sc -> bus_dev == NULL ) { error = ENXIO ; goto failed ; } dinfo = device_get_ivars ( sc -> bus_dev ) ; dinfo -> addrspace = BHNDB_ADDRSPACE_BRIDGED ; return ( bus_generic_attach ( dev ) ) ; failed : BHNDB_LOCK_DESTROY ( sc ) ; if ( sc -> bus_res != NULL ) bhndb_free_resources ( sc -> bus_res ) ; return ( error ) ; }
Helper function that must be called by subclass bhndb(4) drivers
 when implementing DEVICE_ATTACH() before calling any bhnd(4) or bhndb(4)
 APIs on the bridge device.
Helper function that must be called by subclass bhndb ( 4 ) drivers when implementing DEVICE_ATTACH () before calling any bhnd ( 4 ) or bhndb ( 4 ) APIs on the bridge device .
/* Read our chip identification data */ /* Populate generic resource allocation state. */ /* Attach our bridged bus device */ /* Configure address space */ /* Finish attach */