FreeBSD/sys/isa/isa_common.c
/*
 * Find a working set of port regions for a child using the ranges
 * in *config  and return the regions in *result. Returns non-zero if
 * a set of ranges was found.
 */
Find a working set of port regions for a child using the ranges
in *config  and return the regions in *result. Returns non-zero if
a set of ranges was found.
Find a working set of port regions for a child using the ranges in * config and return the regions in * result . Returns non - zero if a set of ranges was found .
static int
isa_find_port(device_t child, struct isa_config *config,
    struct isa_config *result)
{
	int success, i;
	struct resource *res[ISA_NPORT];
	for (i = 0; i < ISA_NPORT; i++) {
		bus_delete_resource(child, SYS_RES_IOPORT, i);
		res[i] = NULL;
	}
	success = 1;
	result->ic_nport = config->ic_nport;
	for (i = 0; i < config->ic_nport; i++) {
		uint32_t start, end, size, align;
		size = config->ic_port[i].ir_size;
		if (size == 0) {
			result->ic_port[i].ir_start = 0;
			result->ic_port[i].ir_end = 0;
			result->ic_port[i].ir_size = 0;
			result->ic_port[i].ir_align = 0;
			continue;
		}
		for (start = config->ic_port[i].ir_start,
			     end = config->ic_port[i].ir_end,
			     align = config->ic_port[i].ir_align;
		     start + size - 1 <= end;
		     start += align) {
			bus_set_resource(child, SYS_RES_IOPORT, i,
					 start, size);
			res[i] = bus_alloc_resource_any(child,
			    SYS_RES_IOPORT, &i,
			    rman_make_alignment_flags(align) );
			if (res[i]) {
				result->ic_port[i].ir_start = start;
				result->ic_port[i].ir_end = start + size - 1;
				result->ic_port[i].ir_size = size;
				result->ic_port[i].ir_align = align;
				break;
			}
		}
		if (!res[i]) {
			success = 0;
			break;
		}
	}
	for (i = 0; i < ISA_NPORT; i++) {
		if (res[i])
			bus_release_resource(child, SYS_RES_IOPORT,
					     i, res[i]);
	}
	return success;
}
static int isa_find_port ( device_t child , struct isa_config * config , struct isa_config * result ) { int success , i ; struct resource * res [ ISA_NPORT ] ; for ( i = 0 ; i < ISA_NPORT ; i ++ ) { bus_delete_resource ( child , SYS_RES_IOPORT , i ) ; res [ i ] = NULL ; } success = 1 ; result -> ic_nport = config -> ic_nport ; for ( i = 0 ; i < config -> ic_nport ; i ++ ) { uint32_t start , end , size , align ; size = config -> ic_port [ i ] . ir_size ; if ( size == 0 ) { result -> ic_port [ i ] . ir_start = 0 ; result -> ic_port [ i ] . ir_end = 0 ; result -> ic_port [ i ] . ir_size = 0 ; result -> ic_port [ i ] . ir_align = 0 ; continue ; } for ( start = config -> ic_port [ i ] . ir_start , end = config -> ic_port [ i ] . ir_end , align = config -> ic_port [ i ] . ir_align ; start + size - 1 <= end ; start += align ) { bus_set_resource ( child , SYS_RES_IOPORT , i , start , size ) ; res [ i ] = bus_alloc_resource_any ( child , SYS_RES_IOPORT , & i , rman_make_alignment_flags ( align ) ) ; if ( res [ i ] ) { result -> ic_port [ i ] . ir_start = start ; result -> ic_port [ i ] . ir_end = start + size - 1 ; result -> ic_port [ i ] . ir_size = size ; result -> ic_port [ i ] . ir_align = align ; break ; } } if ( ! res [ i ] ) { success = 0 ; break ; } } for ( i = 0 ; i < ISA_NPORT ; i ++ ) { if ( res [ i ] ) bus_release_resource ( child , SYS_RES_IOPORT , i , res [ i ] ) ; } return success ; }
Find a working set of port regions for a child using the ranges
 in *config  and return the regions in *result.
Find a working set of port regions for a child using the ranges in * config and return the regions in * result .
/*
	 * First clear out any existing resource definitions.
	 */ /* the PnP device may have a null resource as filler */ /* !RF_ACTIVE */ /*
		 * If we didn't find a place for port range i, then 
		 * give up now.
		 */