FreeBSD/sys/x86/iommu/intel_utils.c
/*
 * Find a best fit mgaw for the given maxaddr:
 *   - if allow_less is false, must find sagaw which maps all requested
 *     addresses (used by identity mappings);
 *   - if allow_less is true, and no supported sagaw can map all requested
 *     address space, accept the biggest sagaw, whatever is it.
 */
Find a best fit mgaw for the given maxaddr:
- if allow_less is false, must find sagaw which maps all requested
addresses (used by identity mappings);
- if allow_less is true, and no supported sagaw can map all requested
address space, accept the biggest sagaw, whatever is it.
Find a best fit mgaw for the given maxaddr : - if allow_less is false must find sagaw which maps all requested addresses ( used by identity mappings ) ; - if allow_less is true and no supported sagaw can map all requested address space accept the biggest sagaw whatever is it .
int
dmar_maxaddr2mgaw(struct dmar_unit *unit, dmar_gaddr_t maxaddr, bool allow_less)
{
	int i;
	for (i = 0; i < nitems(sagaw_bits); i++) {
		if ((1ULL << sagaw_bits[i].agaw) >= maxaddr &&
		    (DMAR_CAP_SAGAW(unit->hw_cap) & sagaw_bits[i].cap) != 0)
			break;
	}
	if (allow_less && i == nitems(sagaw_bits)) {
		do {
			i--;
		} while ((DMAR_CAP_SAGAW(unit->hw_cap) & sagaw_bits[i].cap)
		    == 0);
	}
	if (i < nitems(sagaw_bits))
		return (sagaw_bits[i].agaw);
	KASSERT(0, ("no mgaw for maxaddr %jx allow_less %d",
	    (uintmax_t) maxaddr, allow_less));
	return (-1);
}
int dmar_maxaddr2mgaw ( struct dmar_unit * unit , dmar_gaddr_t maxaddr , bool allow_less ) { int i ; for ( i = 0 ; i < nitems ( sagaw_bits ) ; i ++ ) { if ( ( 1ULL << sagaw_bits [ i ] . agaw ) >= maxaddr && ( DMAR_CAP_SAGAW ( unit -> hw_cap ) & sagaw_bits [ i ] . cap ) != 0 ) break ; } if ( allow_less && i == nitems ( sagaw_bits ) ) { do { i -- ; } while ( ( DMAR_CAP_SAGAW ( unit -> hw_cap ) & sagaw_bits [ i ] . cap ) == 0 ) ; } if ( i < nitems ( sagaw_bits ) ) return ( sagaw_bits [ i ] . agaw ) ; KASSERT ( 0 , ( " " , ( uintmax_t ) maxaddr , allow_less ) ) ; return ( -1 ) ; }
Find a best fit mgaw for the given maxaddr:
   - if allow_less is false, must find sagaw which maps all requested
     addresses (used by identity mappings);
   - if allow_less is true, and no supported sagaw can map all requested
     address space, accept the biggest sagaw, whatever is it.
Find a best fit mgaw for the given maxaddr : - if allow_less is false must find sagaw which maps all requested addresses ( used by identity mappings ) ; - if allow_less is true and no supported sagaw can map all requested address space accept the biggest sagaw whatever is it .