FreeBSD/sys/i386/i386/i686_mem.c
/*
 * Work out how many ranges we support, initialise storage for them,
 * and fetch the initial settings.
 */
Work out how many ranges we support, initialise storage for them,
and fetch the initial settings.
Work out how many ranges we support initialise storage for them and fetch the initial settings .
static void
i686_mrinit(struct mem_range_softc *sc)
{
	struct mem_range_desc *mrd;
	u_int regs[4];
	int i, nmdesc = 0, pabits;
	mtrrcap = rdmsr(MSR_MTRRcap);
	mtrrdef = rdmsr(MSR_MTRRdefType);
	if (!(mtrrdef & MTRR_DEF_ENABLE)) {
		if (bootverbose)
			printf("CPU supports MTRRs but not enabled\n");
		return;
	}
	nmdesc = mtrrcap & MTRR_CAP_VCNT;
	if (bootverbose)
		printf("Pentium Pro MTRR support enabled\n");
	if (cpu_exthigh >= 0x80000008) {
		do_cpuid(0x80000008, regs);
		pabits = regs[0] & 0xff;
	} else
		pabits = 36;
	mtrr_physmask = ((1ULL << pabits) - 1) & ~0xfffULL;
	if ((mtrrcap & MTRR_CAP_FIXED) && (mtrrdef & MTRR_DEF_FIXED_ENABLE)) {
		sc->mr_cap = MR686_FIXMTRR;
		nmdesc += MTRR_N64K + MTRR_N16K + MTRR_N4K;
	}
	sc->mr_desc = malloc(nmdesc * sizeof(struct mem_range_desc), M_MEMDESC,
	    M_WAITOK | M_ZERO);
	sc->mr_ndesc = nmdesc;
	mrd = sc->mr_desc;
	if (sc->mr_cap & MR686_FIXMTRR) {
		for (i = 0; i < MTRR_N64K; i++, mrd++) {
			mrd->mr_base = i * 0x10000;
			mrd->mr_len = 0x10000;
			mrd->mr_flags = MDF_FIXBASE | MDF_FIXLEN |
			    MDF_FIXACTIVE;
		}
		for (i = 0; i < MTRR_N16K; i++, mrd++) {
			mrd->mr_base = i * 0x4000 + 0x80000;
			mrd->mr_len = 0x4000;
			mrd->mr_flags = MDF_FIXBASE | MDF_FIXLEN |
			    MDF_FIXACTIVE;
		}
		for (i = 0; i < MTRR_N4K; i++, mrd++) {
			mrd->mr_base = i * 0x1000 + 0xc0000;
			mrd->mr_len = 0x1000;
			mrd->mr_flags = MDF_FIXBASE | MDF_FIXLEN |
			    MDF_FIXACTIVE;
		}
	}
	i686_mrfetch(sc);
	mrd = sc->mr_desc;
	for (i = 0; i < sc->mr_ndesc; i++, mrd++) {
		if (mrd->mr_flags & MDF_ACTIVE)
			mrd->mr_flags |= MDF_FIRMWARE;
	}
}
static void i686_mrinit ( struct mem_range_softc * sc ) { struct mem_range_desc * mrd ; u_int regs [ 4 ] ; int i , nmdesc = 0 , pabits ; mtrrcap = rdmsr ( MSR_MTRRcap ) ; mtrrdef = rdmsr ( MSR_MTRRdefType ) ; if ( ! ( mtrrdef & MTRR_DEF_ENABLE ) ) { if ( bootverbose ) printf ( " \n " ) ; return ; } nmdesc = mtrrcap & MTRR_CAP_VCNT ; if ( bootverbose ) printf ( " \n " ) ; if ( cpu_exthigh >= 0x80000008 ) { do_cpuid ( 0x80000008 , regs ) ; pabits = regs [ 0 ] & 0xff ; } else pabits = 36 ; mtrr_physmask = ( ( 1ULL << pabits ) - 1 ) & ~ 0xfffULL ; if ( ( mtrrcap & MTRR_CAP_FIXED ) && ( mtrrdef & MTRR_DEF_FIXED_ENABLE ) ) { sc -> mr_cap = MR686_FIXMTRR ; nmdesc += MTRR_N64K + MTRR_N16K + MTRR_N4K ; } sc -> mr_desc = malloc ( nmdesc * sizeof ( struct mem_range_desc ) , M_MEMDESC , M_WAITOK | M_ZERO ) ; sc -> mr_ndesc = nmdesc ; mrd = sc -> mr_desc ; if ( sc -> mr_cap & MR686_FIXMTRR ) { for ( i = 0 ; i < MTRR_N64K ; i ++ , mrd ++ ) { mrd -> mr_base = i * 0x10000 ; mrd -> mr_len = 0x10000 ; mrd -> mr_flags = MDF_FIXBASE | MDF_FIXLEN | MDF_FIXACTIVE ; } for ( i = 0 ; i < MTRR_N16K ; i ++ , mrd ++ ) { mrd -> mr_base = i * 0x4000 + 0x80000 ; mrd -> mr_len = 0x4000 ; mrd -> mr_flags = MDF_FIXBASE | MDF_FIXLEN | MDF_FIXACTIVE ; } for ( i = 0 ; i < MTRR_N4K ; i ++ , mrd ++ ) { mrd -> mr_base = i * 0x1000 + 0xc0000 ; mrd -> mr_len = 0x1000 ; mrd -> mr_flags = MDF_FIXBASE | MDF_FIXLEN | MDF_FIXACTIVE ; } } i686_mrfetch ( sc ) ; mrd = sc -> mr_desc ; for ( i = 0 ; i < sc -> mr_ndesc ; i ++ , mrd ++ ) { if ( mrd -> mr_flags & MDF_ACTIVE ) mrd -> mr_flags |= MDF_FIRMWARE ; } }
Work out how many ranges we support, initialise storage for them,
 and fetch the initial settings.
Work out how many ranges we support initialise storage for them and fetch the initial settings .
/* For now, bail out if MTRRs are not enabled. */ /*
	 * Determine the size of the PhysMask and PhysBase fields in
	 * the variable range MTRRs.  If the extended CPUID 0x80000008
	 * is present, use that to figure out how many physical
	 * address bits the CPU supports.  Otherwise, default to 36
	 * address bits.
	 */ /* If fixed MTRRs supported and enabled. */ /* Populate the fixed MTRR entries' base/length. */ /*
	 * Get current settings, anything set now is considered to
	 * have been set by the firmware. (XXX has something already
	 * played here?)
	 */