unsigned long *res_ptr = ioc->res_hint; 
unsigned long *res_ptr; 
sba_search_bitmap(struct ioc *ioc, unsigned long bits_wanted){	unsigned long *res_ptr = ioc->res_hint;	unsigned long *res_end = (unsigned long *) &(ioc->res_map[ioc->res_size]);	unsigned long pide = ~0UL;	ASSERT(((unsigned long) ioc->res_hint & (sizeof(unsigned long) - 1UL)) == 0);	ASSERT(res_ptr < res_end);	/*	 * N.B.  REO/Grande defect AR2305 can cause TLB fetch timeouts	 * if a TLB entry is purged while in use.  sba_mark_invalid()	 * purges IOTLB entries in power-of-two sizes, so we also	 * allocate IOVA space in power-of-two sizes.	 */	bits_wanted = 1UL << get_iovp_order(bits_wanted << iovp_shift);	if (likely(bits_wanted == 1)) {		unsigned int bitshiftcnt;		for(; res_ptr < res_end ; res_ptr++) {			if (likely(*res_ptr != ~0UL)) {				bitshiftcnt = ffz(*res_ptr);				*res_ptr |= (1UL << bitshiftcnt);				pide = ((unsigned long)res_ptr - (unsigned long)ioc->res_map);				pide <<= 3;	/* convert to bit address */				pide += bitshiftcnt;				ioc->res_bitshift = bitshiftcnt + bits_wanted;				goto found_it;			}		}		goto not_found;	}		if (likely(bits_wanted <= BITS_PER_LONG/2)) {		/*		** Search the resource bit map on well-aligned values.		** "o" is the alignment.		** We need the alignment to invalidate I/O TLB using		** SBA HW features in the unmap path.		*/		unsigned long o = 1 << get_iovp_order(bits_wanted << iovp_shift);		uint bitshiftcnt = ROUNDUP(ioc->res_bitshift, o);		unsigned long mask, base_mask;		base_mask = RESMAP_MASK(bits_wanted);		mask = base_mask << bitshiftcnt;		DBG_RES("%s() o %ld %p", __FUNCTION__, o, res_ptr);		for(; res_ptr < res_end ; res_ptr++)		{ 			DBG_RES("    %p %lx %lx\n", res_ptr, mask, *res_ptr);			ASSERT(0 != mask);			for (; mask ; mask <<= o, bitshiftcnt += o) {				if(0 == ((*res_ptr) & mask)) {					*res_ptr |= mask;     /* mark resources busy! */					pide = ((unsigned long)res_ptr - (unsigned long)ioc->res_map);					pide <<= 3;	/* convert to bit address */					pide += bitshiftcnt;					ioc->res_bitshift = bitshiftcnt + bits_wanted;					goto found_it;				}			}			bitshiftcnt = 0;			mask = base_mask;		}	} else {		int qwords, bits, i;		unsigned long *end;		qwords = bits_wanted >> 6; /* /64 */		bits = bits_wanted - (qwords * BITS_PER_LONG);		end = res_end - qwords;		for (; res_ptr < end; res_ptr++) {			for (i = 0 ; i < qwords ; i++) {				if (res_ptr[i] != 0)					goto next_ptr;			}			if (bits && res_ptr[i] && (__ffs(res_ptr[i]) < bits))				continue;			/* Found it, mark it */			for (i = 0 ; i < qwords ; i++)				res_ptr[i] = ~0UL;			res_ptr[i] |= RESMAP_MASK(bits);			pide = ((unsigned long)res_ptr - (unsigned long)ioc->res_map);			pide <<= 3;	/* convert to bit address */			res_ptr += qwords;			ioc->res_bitshift = bits;			goto found_it;next_ptr:			;		}	}not_found:	prefetch(ioc->res_map);	ioc->res_hint = (unsigned long *) ioc->res_map;	ioc->res_bitshift = 0;	return (pide);found_it:	ioc->res_hint = res_ptr;	return (pide);}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/5f6602a101993592b437b801c401443bec65d0cf/sba_iommu.c/clean/arch/ia64/hp/common/sba_iommu.c