FreeBSD/sys/dev/bhnd/bhndb/bhndb.c
/**
 * Attempt to allocate/retain a dynamic register window for @p r, returning
 * the retained window.
 * 
 * @param sc The bhndb driver state.
 * @param r The resource for which a window will be retained.
 */
Attempt to allocate/retain a dynamic register window for @p r, returning
the retained window.

@param sc The bhndb driver state.
@param r The resource for which a window will be retained.
Attempt to allocate / retain a dynamic register window for @p r returning the retained window . @param sc The bhndb driver state . @param r The resource for which a window will be retained .
static struct bhndb_dw_alloc *
bhndb_retain_dynamic_window(struct bhndb_softc *sc, struct resource *r)
{
	struct bhndb_dw_alloc	*dwa;
	rman_res_t		 r_start, r_size;
	int			 error;
	BHNDB_LOCK_ASSERT(sc, MA_OWNED);
	r_start = rman_get_start(r);
	r_size = rman_get_size(r);
	dwa = bhndb_dw_find_mapping(sc->bus_res, r_start, r_size);
	if (dwa != NULL) {
		if (bhndb_dw_retain(sc->bus_res, dwa, r) == 0)
			return (dwa);
		return (NULL);
	}
	dwa = bhndb_dw_next_free(sc->bus_res);
	if (dwa == NULL) {
		return (NULL);
	}
	error = bhndb_dw_set_addr(sc->dev, sc->bus_res, dwa, rman_get_start(r),
	    rman_get_size(r));
	if (error) {
		device_printf(sc->dev, "dynamic window initialization "
			"for 0x%llx-0x%llx failed: %d\n",
			(unsigned long long) r_start,
			(unsigned long long) r_start + r_size - 1,
			error);
		return (NULL);
	}
	if (bhndb_dw_retain(sc->bus_res, dwa, r))
		return (NULL);
	return (dwa);
}
static struct bhndb_dw_alloc * bhndb_retain_dynamic_window ( struct bhndb_softc * sc , struct resource * r ) { struct bhndb_dw_alloc * dwa ; rman_res_t r_start , r_size ; int error ; BHNDB_LOCK_ASSERT ( sc , MA_OWNED ) ; r_start = rman_get_start ( r ) ; r_size = rman_get_size ( r ) ; dwa = bhndb_dw_find_mapping ( sc -> bus_res , r_start , r_size ) ; if ( dwa != NULL ) { if ( bhndb_dw_retain ( sc -> bus_res , dwa , r ) == 0 ) return ( dwa ) ; return ( NULL ) ; } dwa = bhndb_dw_next_free ( sc -> bus_res ) ; if ( dwa == NULL ) { return ( NULL ) ; } error = bhndb_dw_set_addr ( sc -> dev , sc -> bus_res , dwa , rman_get_start ( r ) , rman_get_size ( r ) ) ; if ( error ) { device_printf ( sc -> dev , " " " \n " , ( unsigned long long ) r_start , ( unsigned long long ) r_start + r_size - 1 , error ) ; return ( NULL ) ; } if ( bhndb_dw_retain ( sc -> bus_res , dwa , r ) ) return ( NULL ) ; return ( dwa ) ; }
Attempt to allocate/retain a dynamic register window for @p r, returning
 the retained window.
Attempt to allocate / retain a dynamic register window for @p r returning the retained window .
/* Look for an existing dynamic window we can reference */ /* Otherwise, try to reserve a free window */ /* No free windows */ /* Set the window target */ /* Add our reservation */