FreeBSD/sys/dev/bhnd/cores/chipc/chipc.c
/**
 * Retain an RF_ACTIVE reference to the region mapping @p r, and
 * configure @p r with its subregion values.
 *
 * @param sc Driver instance state.
 * @param child Requesting child device.
 * @param type resource type of @p r.
 * @param rid resource id of @p r
 * @param r resource to be activated.
 * @param req_direct If true, failure to allocate a direct bhnd resource
 * will be treated as an error. If false, the resource will not be marked
 * as RF_ACTIVE if bhnd direct resource allocation fails.
 */
Retain an RF_ACTIVE reference to the region mapping @p r, and
configure @p r with its subregion values.

@param sc Driver instance state.
@param child Requesting child device.
@param type resource type of @p r.
@param rid resource id of @p r
@param r resource to be activated.
@param req_direct If true, failure to allocate a direct bhnd resource
will be treated as an error. If false, the resource will not be marked
as RF_ACTIVE if bhnd direct resource allocation fails.
Retain an RF_ACTIVE reference to the region mapping @p r and configure @p r with its subregion values . @param sc Driver instance state . @param child Requesting child device . @param type resource type of @p r . @param rid resource id of @p r @param r resource to be activated . @param req_direct If true failure to allocate a direct bhnd resource will be treated as an error . If false the resource will not be marked as RF_ACTIVE if bhnd direct resource allocation fails .
static int
chipc_try_activate_resource(struct chipc_softc *sc, device_t child, int type,
    int rid, struct resource *r, bool req_direct)
{
	struct rman		*rm;
	struct chipc_region	*cr;
	bhnd_size_t		 cr_offset;
	rman_res_t		 r_start, r_end, r_size;
	int			 error;
	rm = chipc_get_rman(sc, type);
	if (rm == NULL || !rman_is_region_manager(r, rm))
		return (EINVAL);
	r_start = rman_get_start(r);
	r_end = rman_get_end(r);
	r_size = rman_get_size(r);
	cr = chipc_find_region(sc, r_start, r_end);
	if (cr == NULL)
		return (EINVAL);
	cr_offset = r_start - cr->cr_addr;
	if ((error = chipc_retain_region(sc, cr, RF_ACTIVE)))
		return (error);
	if (cr->cr_res->direct) {
		error = chipc_init_child_resource(r, cr->cr_res->res,
		    cr_offset, r_size);
		if (error)
			goto cleanup;
		if ((error = rman_activate_resource(r)))
			goto cleanup;
	} else if (req_direct) {
		error = ENOMEM;
		goto cleanup;
	}
	return (0);
cleanup:
	chipc_release_region(sc, cr, RF_ACTIVE);
	return (error);
}
static int chipc_try_activate_resource ( struct chipc_softc * sc , device_t child , int type , int rid , struct resource * r , bool req_direct ) { struct rman * rm ; struct chipc_region * cr ; bhnd_size_t cr_offset ; rman_res_t r_start , r_end , r_size ; int error ; rm = chipc_get_rman ( sc , type ) ; if ( rm == NULL || ! rman_is_region_manager ( r , rm ) ) return ( EINVAL ) ; r_start = rman_get_start ( r ) ; r_end = rman_get_end ( r ) ; r_size = rman_get_size ( r ) ; cr = chipc_find_region ( sc , r_start , r_end ) ; if ( cr == NULL ) return ( EINVAL ) ; cr_offset = r_start - cr -> cr_addr ; if ( ( error = chipc_retain_region ( sc , cr , RF_ACTIVE ) ) ) return ( error ) ; if ( cr -> cr_res -> direct ) { error = chipc_init_child_resource ( r , cr -> cr_res -> res , cr_offset , r_size ) ; if ( error ) goto cleanup ; if ( ( error = rman_activate_resource ( r ) ) ) goto cleanup ; } else if ( req_direct ) { error = ENOMEM ; goto cleanup ; } return ( 0 ) ; cleanup : chipc_release_region ( sc , cr , RF_ACTIVE ) ; return ( error ) ; }
Retain an RF_ACTIVE reference to the region mapping @p r, and
 configure @p r with its subregion values.
Retain an RF_ACTIVE reference to the region mapping @p r and configure @p r with its subregion values .
/* Find the corresponding chipc region */ /* Calculate subregion offset within the chipc region */ /* Retain (and activate, if necessary) the chipc region */ /* Configure child resource with its subregion values. */ /* Mark active */