FreeBSD/sys/dev/pccard/pccard.c
/*
 * Initialize a PCCARD function.  May be called as long as the function is
 * disabled.
 *
 * Note: pccard_function_init should not keep resources allocated.  It should
 * only set them up ala isa pnp, set the values in the rl lists, and return.
 * Any resource held after pccard_function_init is called is a bug.  However,
 * the bus routines to get the resources also assume that pccard_function_init
 * does this, so they need to be fixed too.
 */
Initialize a PCCARD function.  May be called as long as the function is
disabled.

pccard_function_init should not keep resources allocated.  It should
only set them up ala isa pnp, set the values in the rl lists, and return.
Any resource held after pccard_function_init is called is a bug.  However,
the bus routines to get the resources also assume that pccard_function_init
does this, so they need to be fixed too.
Initialize a PCCARD function . May be called as long as the function is disabled . pccard_function_init should not keep resources allocated . It should only set them up ala isa pnp set the values in the rl lists and return . Any resource held after pccard_function_init is called is a bug . However the bus routines to get the resources also assume that pccard_function_init does this so they need to be fixed too .
static void
pccard_function_init(struct pccard_function *pf, int entry)
{
	struct pccard_config_entry *cfe;
	struct pccard_ivar *devi = PCCARD_IVAR(pf->dev);
	struct resource_list *rl = &devi->resources;
	struct resource_list_entry *rle;
	struct resource *r = 0;
	struct pccard_ce_iospace *ios;
	struct pccard_ce_memspace *mems;
	device_t bus;
	rman_res_t start, end, len;
	int i, rid, spaces;
	if (pf->pf_flags & PFF_ENABLED) {
		printf("pccard_function_init: function is enabled");
		return;
	}
	if (pf->cfe != NULL)
		return;
	bus = device_get_parent(pf->dev);
	STAILQ_FOREACH(cfe, &pf->cfe_head, cfe_list) {
		if (cfe->iftype != PCCARD_IFTYPE_IO)
			continue;
		if (entry != -1 && cfe->number != entry)
			continue;
		spaces = 0;
		for (i = 0; i < cfe->num_iospace; i++) {
			ios = cfe->iospace + i;
			start = ios->start;
			if (start)
				end = start + ios->length - 1;
			else
				end = ~0;
			DEVPRINTF((bus, "I/O rid %d start %#jx end %#jx\n",
			    i, start, end));
			rid = i;
			len = ios->length;
			r = bus_alloc_resource(bus, SYS_RES_IOPORT, &rid,
			    start, end, len, rman_make_alignment_flags(len));
			if (r == NULL) {
				DEVPRINTF((bus, "I/O rid %d failed\n", i));
				goto not_this_one;
			}
			rle = resource_list_add(rl, SYS_RES_IOPORT,
			    rid, rman_get_start(r), rman_get_end(r), len);
			if (rle == NULL)
				panic("Cannot add resource rid %d IOPORT", rid);
			rle->res = r;
			spaces++;
		}
		for (i = 0; i < cfe->num_memspace; i++) {
			mems = cfe->memspace + i;
			start = mems->cardaddr + mems->hostaddr;
			if (start)
				end = start + mems->length - 1;
			else
				end = ~0;
			DEVPRINTF((bus, "Memory rid %d start %#jx end %#jx\ncardaddr %#jx hostaddr %#jx length %#jx\n",
			    i, start, end, mems->cardaddr, mems->hostaddr,
			    mems->length));
			rid = i;
			len = mems->length;
			r = bus_alloc_resource(bus, SYS_RES_MEMORY, &rid,
			    start, end, len, rman_make_alignment_flags(len));
			if (r == NULL) {
				DEVPRINTF((bus, "Memory rid %d failed\n", i));
				continue;
			}
			rle = resource_list_add(rl, SYS_RES_MEMORY,
			    rid, rman_get_start(r), rman_get_end(r), len);
			if (rle == NULL)
				panic("Cannot add resource rid %d MEM", rid);
			rle->res = r;
			spaces++;
		}
		if (spaces == 0) {
			DEVPRINTF((bus, "Neither memory nor I/O mapped\n"));
			goto not_this_one;
		}
		if (cfe->irqmask) {
			rid = 0;
			r = bus_alloc_resource_any(bus, SYS_RES_IRQ, &rid,
			    RF_SHAREABLE);
			if (r == NULL) {
				DEVPRINTF((bus, "IRQ rid %d failed\n", rid));
				goto not_this_one;
			}
			rle = resource_list_add(rl, SYS_RES_IRQ, rid,
			    rman_get_start(r), rman_get_end(r), 1);
			if (rle == NULL)
				panic("Cannot add resource rid %d IRQ", rid);
			rle->res = r;
		}
		pf->cfe = cfe;
		break;
	    not_this_one:;
		DEVPRVERBOSE((bus, "Allocation failed for cfe %d\n",
		    cfe->number));
		resource_list_purge(rl);
	}
}
static void pccard_function_init ( struct pccard_function * pf , int entry ) { struct pccard_config_entry * cfe ; struct pccard_ivar * devi = PCCARD_IVAR ( pf -> dev ) ; struct resource_list * rl = & devi -> resources ; struct resource_list_entry * rle ; struct resource * r = 0 ; struct pccard_ce_iospace * ios ; struct pccard_ce_memspace * mems ; device_t bus ; rman_res_t start , end , len ; int i , rid , spaces ; if ( pf -> pf_flags & PFF_ENABLED ) { printf ( " " ) ; return ; } if ( pf -> cfe != NULL ) return ; bus = device_get_parent ( pf -> dev ) ; STAILQ_FOREACH ( cfe , & pf -> cfe_head , cfe_list ) { if ( cfe -> iftype != PCCARD_IFTYPE_IO ) continue ; if ( entry != -1 && cfe -> number != entry ) continue ; spaces = 0 ; for ( i = 0 ; i < cfe -> num_iospace ; i ++ ) { ios = cfe -> iospace + i ; start = ios -> start ; if ( start ) end = start + ios -> length - 1 ; else end = ~ 0 ; DEVPRINTF ( ( bus , " \n " , i , start , end ) ) ; rid = i ; len = ios -> length ; r = bus_alloc_resource ( bus , SYS_RES_IOPORT , & rid , start , end , len , rman_make_alignment_flags ( len ) ) ; if ( r == NULL ) { DEVPRINTF ( ( bus , " \n " , i ) ) ; goto not_this_one ; } rle = resource_list_add ( rl , SYS_RES_IOPORT , rid , rman_get_start ( r ) , rman_get_end ( r ) , len ) ; if ( rle == NULL ) panic ( " " , rid ) ; rle -> res = r ; spaces ++ ; } for ( i = 0 ; i < cfe -> num_memspace ; i ++ ) { mems = cfe -> memspace + i ; start = mems -> cardaddr + mems -> hostaddr ; if ( start ) end = start + mems -> length - 1 ; else end = ~ 0 ; DEVPRINTF ( ( bus , " \n \n " , i , start , end , mems -> cardaddr , mems -> hostaddr , mems -> length ) ) ; rid = i ; len = mems -> length ; r = bus_alloc_resource ( bus , SYS_RES_MEMORY , & rid , start , end , len , rman_make_alignment_flags ( len ) ) ; if ( r == NULL ) { DEVPRINTF ( ( bus , " \n " , i ) ) ; continue ; } rle = resource_list_add ( rl , SYS_RES_MEMORY , rid , rman_get_start ( r ) , rman_get_end ( r ) , len ) ; if ( rle == NULL ) panic ( " " , rid ) ; rle -> res = r ; spaces ++ ; } if ( spaces == 0 ) { DEVPRINTF ( ( bus , " \n " ) ) ; goto not_this_one ; } if ( cfe -> irqmask ) { rid = 0 ; r = bus_alloc_resource_any ( bus , SYS_RES_IRQ , & rid , RF_SHAREABLE ) ; if ( r == NULL ) { DEVPRINTF ( ( bus , " \n " , rid ) ) ; goto not_this_one ; } rle = resource_list_add ( rl , SYS_RES_IRQ , rid , rman_get_start ( r ) , rman_get_end ( r ) , 1 ) ; if ( rle == NULL ) panic ( " " , rid ) ; rle -> res = r ; } pf -> cfe = cfe ; break ; not_this_one : ; DEVPRVERBOSE ( ( bus , " \n " , cfe -> number ) ) ; resource_list_purge ( rl ) ; } }
Initialize a PCCARD function.
Initialize a PCCARD function .
/*
	 * Driver probe routine requested a specific entry already
	 * that succeeded.
	 */ /*
	 * walk the list of configuration entries until we find one that
	 * we can allocate all the resources to.
	 */ //				goto not_this_one; /* If we get to here, we've allocated all we need */