FreeBSD/sys/dev/cxgbe/t4_main.c
/*
 * Verify that the memory range specified by the memtype/offset/len pair is
 * valid and lies entirely within the memtype specified.  The global address of
 * the start of the range is returned in addr.
 */
Verify that the memory range specified by the memtype/offset/len pair is
valid and lies entirely within the memtype specified.  The global address of
the start of the range is returned in addr.
Verify that the memory range specified by the memtype / offset / len pair is valid and lies entirely within the memtype specified . The global address of the start of the range is returned in addr .
static int
validate_mt_off_len(struct adapter *sc, int mtype, uint32_t off, int len,
    uint32_t *addr)
{
	uint32_t em, addr_len, maddr;
	if (off & 3 || len & 3 || len == 0)
		return (EINVAL);
	em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
	switch (fwmtype_to_hwmtype(mtype)) {
	case MEM_EDC0:
		if (!(em & F_EDRAM0_ENABLE))
			return (EINVAL);
		addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
		maddr = G_EDRAM0_BASE(addr_len) << 20;
		break;
	case MEM_EDC1:
		if (!(em & F_EDRAM1_ENABLE))
			return (EINVAL);
		addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
		maddr = G_EDRAM1_BASE(addr_len) << 20;
		break;
	case MEM_MC:
		if (!(em & F_EXT_MEM_ENABLE))
			return (EINVAL);
		addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
		maddr = G_EXT_MEM_BASE(addr_len) << 20;
		break;
	case MEM_MC1:
		if (!is_t5(sc) || !(em & F_EXT_MEM1_ENABLE))
			return (EINVAL);
		addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
		maddr = G_EXT_MEM1_BASE(addr_len) << 20;
		break;
	default:
		return (EINVAL);
	}
	*addr = maddr + off;	
	return (validate_mem_range(sc, *addr, len));
}
static int validate_mt_off_len ( struct adapter * sc , int mtype , uint32_t off , int len , uint32_t * addr ) { uint32_t em , addr_len , maddr ; if ( off & 3 || len & 3 || len == 0 ) return ( EINVAL ) ; em = t4_read_reg ( sc , A_MA_TARGET_MEM_ENABLE ) ; switch ( fwmtype_to_hwmtype ( mtype ) ) { case MEM_EDC0 : if ( ! ( em & F_EDRAM0_ENABLE ) ) return ( EINVAL ) ; addr_len = t4_read_reg ( sc , A_MA_EDRAM0_BAR ) ; maddr = G_EDRAM0_BASE ( addr_len ) << 20 ; break ; case MEM_EDC1 : if ( ! ( em & F_EDRAM1_ENABLE ) ) return ( EINVAL ) ; addr_len = t4_read_reg ( sc , A_MA_EDRAM1_BAR ) ; maddr = G_EDRAM1_BASE ( addr_len ) << 20 ; break ; case MEM_MC : if ( ! ( em & F_EXT_MEM_ENABLE ) ) return ( EINVAL ) ; addr_len = t4_read_reg ( sc , A_MA_EXT_MEMORY_BAR ) ; maddr = G_EXT_MEM_BASE ( addr_len ) << 20 ; break ; case MEM_MC1 : if ( ! is_t5 ( sc ) || ! ( em & F_EXT_MEM1_ENABLE ) ) return ( EINVAL ) ; addr_len = t4_read_reg ( sc , A_MA_EXT_MEMORY1_BAR ) ; maddr = G_EXT_MEM1_BASE ( addr_len ) << 20 ; break ; default : return ( EINVAL ) ; } * addr = maddr + off ; return ( validate_mem_range ( sc , * addr , len ) ) ; }
Verify that the memory range specified by the memtype/offset/len pair is
 valid and lies entirely within the memtype specified.
Verify that the memory range specified by the memtype / offset / len pair is valid and lies entirely within the memtype specified .
/* Memory can only be accessed in naturally aligned 4 byte units */ /* global address */