FreeBSD/sys/i386/i386/i686_mem.c
/*
 * Fetch the current mtrr settings from the current CPU (assumed to
 * all be in sync in the SMP case).  Note that if we are here, we
 * assume that MTRRs are enabled, and we may or may not have fixed
 * MTRRs.
 */
Fetch the current mtrr settings from the current CPU (assumed to
all be in sync in the SMP case).  Note that if we are here, we
assume that MTRRs are enabled, and we may or may not have fixed
MTRRs.
Fetch the current mtrr settings from the current CPU ( assumed to all be in sync in the SMP case ) . Note that if we are here we assume that MTRRs are enabled and we may or may not have fixed MTRRs .
static void
i686_mrfetch(struct mem_range_softc *sc)
{
	struct mem_range_desc *mrd;
	u_int64_t msrv;
	int i, j, msr;
	mrd = sc->mr_desc;
	if (sc->mr_cap & MR686_FIXMTRR) {
		msr = MSR_MTRR64kBase;
		for (i = 0; i < (MTRR_N64K / 8); i++, msr++) {
			msrv = rdmsr(msr);
			for (j = 0; j < 8; j++, mrd++) {
				mrd->mr_flags =
				    (mrd->mr_flags & ~MDF_ATTRMASK) |
				    i686_mtrr2mrt(msrv & 0xff) | MDF_ACTIVE;
				if (mrd->mr_owner[0] == 0)
					strcpy(mrd->mr_owner, mem_owner_bios);
				msrv = msrv >> 8;
			}
		}
		msr = MSR_MTRR16kBase;
		for (i = 0; i < (MTRR_N16K / 8); i++, msr++) {
			msrv = rdmsr(msr);
			for (j = 0; j < 8; j++, mrd++) {
				mrd->mr_flags =
				    (mrd->mr_flags & ~MDF_ATTRMASK) |
				    i686_mtrr2mrt(msrv & 0xff) | MDF_ACTIVE;
				if (mrd->mr_owner[0] == 0)
					strcpy(mrd->mr_owner, mem_owner_bios);
				msrv = msrv >> 8;
			}
		}
		msr = MSR_MTRR4kBase;
		for (i = 0; i < (MTRR_N4K / 8); i++, msr++) {
			msrv = rdmsr(msr);
			for (j = 0; j < 8; j++, mrd++) {
				mrd->mr_flags =
				    (mrd->mr_flags & ~MDF_ATTRMASK) |
				    i686_mtrr2mrt(msrv & 0xff) | MDF_ACTIVE;
				if (mrd->mr_owner[0] == 0)
					strcpy(mrd->mr_owner, mem_owner_bios);
				msrv = msrv >> 8;
			}
		}
	}
	msr = MSR_MTRRVarBase;
	for (; (mrd - sc->mr_desc) < sc->mr_ndesc; msr += 2, mrd++) {
		msrv = rdmsr(msr);
		mrd->mr_flags = (mrd->mr_flags & ~MDF_ATTRMASK) |
		    i686_mtrr2mrt(msrv & MTRR_PHYSBASE_TYPE);
		mrd->mr_base = msrv & mtrr_physmask;
		msrv = rdmsr(msr + 1);
		mrd->mr_flags = (msrv & MTRR_PHYSMASK_VALID) ?
		    (mrd->mr_flags | MDF_ACTIVE) :
		    (mrd->mr_flags & ~MDF_ACTIVE);
		mrd->mr_len = (~(msrv & mtrr_physmask) &
		    (mtrr_physmask | 0xfffLL)) + 1;
		if (!mrvalid(mrd->mr_base, mrd->mr_len))
			mrd->mr_flags |= MDF_BOGUS;
		if ((mrd->mr_flags & MDF_ACTIVE) && (mrd->mr_owner[0] == 0))
			strcpy(mrd->mr_owner, mem_owner_bios);
	}
}
static void i686_mrfetch ( struct mem_range_softc * sc ) { struct mem_range_desc * mrd ; u_int64_t msrv ; int i , j , msr ; mrd = sc -> mr_desc ; if ( sc -> mr_cap & MR686_FIXMTRR ) { msr = MSR_MTRR64kBase ; for ( i = 0 ; i < ( MTRR_N64K / 8 ) ; i ++ , msr ++ ) { msrv = rdmsr ( msr ) ; for ( j = 0 ; j < 8 ; j ++ , mrd ++ ) { mrd -> mr_flags = ( mrd -> mr_flags & ~ MDF_ATTRMASK ) | i686_mtrr2mrt ( msrv & 0xff ) | MDF_ACTIVE ; if ( mrd -> mr_owner [ 0 ] == 0 ) strcpy ( mrd -> mr_owner , mem_owner_bios ) ; msrv = msrv >> 8 ; } } msr = MSR_MTRR16kBase ; for ( i = 0 ; i < ( MTRR_N16K / 8 ) ; i ++ , msr ++ ) { msrv = rdmsr ( msr ) ; for ( j = 0 ; j < 8 ; j ++ , mrd ++ ) { mrd -> mr_flags = ( mrd -> mr_flags & ~ MDF_ATTRMASK ) | i686_mtrr2mrt ( msrv & 0xff ) | MDF_ACTIVE ; if ( mrd -> mr_owner [ 0 ] == 0 ) strcpy ( mrd -> mr_owner , mem_owner_bios ) ; msrv = msrv >> 8 ; } } msr = MSR_MTRR4kBase ; for ( i = 0 ; i < ( MTRR_N4K / 8 ) ; i ++ , msr ++ ) { msrv = rdmsr ( msr ) ; for ( j = 0 ; j < 8 ; j ++ , mrd ++ ) { mrd -> mr_flags = ( mrd -> mr_flags & ~ MDF_ATTRMASK ) | i686_mtrr2mrt ( msrv & 0xff ) | MDF_ACTIVE ; if ( mrd -> mr_owner [ 0 ] == 0 ) strcpy ( mrd -> mr_owner , mem_owner_bios ) ; msrv = msrv >> 8 ; } } } msr = MSR_MTRRVarBase ; for ( ; ( mrd - sc -> mr_desc ) < sc -> mr_ndesc ; msr += 2 , mrd ++ ) { msrv = rdmsr ( msr ) ; mrd -> mr_flags = ( mrd -> mr_flags & ~ MDF_ATTRMASK ) | i686_mtrr2mrt ( msrv & MTRR_PHYSBASE_TYPE ) ; mrd -> mr_base = msrv & mtrr_physmask ; msrv = rdmsr ( msr + 1 ) ; mrd -> mr_flags = ( msrv & MTRR_PHYSMASK_VALID ) ? ( mrd -> mr_flags | MDF_ACTIVE ) : ( mrd -> mr_flags & ~ MDF_ACTIVE ) ; mrd -> mr_len = ( ~ ( msrv & mtrr_physmask ) & ( mtrr_physmask | 0xfffLL ) ) + 1 ; if ( ! mrvalid ( mrd -> mr_base , mrd -> mr_len ) ) mrd -> mr_flags |= MDF_BOGUS ; if ( ( mrd -> mr_flags & MDF_ACTIVE ) && ( mrd -> mr_owner [ 0 ] == 0 ) ) strcpy ( mrd -> mr_owner , mem_owner_bios ) ; } }
Fetch the current mtrr settings from the current CPU (assumed to
 all be in sync in the SMP case).
Fetch the current mtrr settings from the current CPU ( assumed to all be in sync in the SMP case ) .
/* Get fixed-range MTRRs. */ /* Get remainder which must be variable MTRRs. */ /* Compute the range from the mask. Ick. */ /* If unclaimed and active, must be the BIOS. */