background image

Vol. 3A 11-31

MEMORY CACHE CONTROL

11.11.7.2   MemTypeSet() Function

The MemTypeSet() function in Example 11-6 sets a MTRR for the physical memory range specified by the parame-
ters base and size to the type specified by type. The base address and size are multiples of 4 KBytes and the size 
is not 0.

Example 11-6.  MemTypeSet Pseudocode

IF CPU_FEATURES.MTRR (* processor supports MTRRs *)

THEN

IF BASE and SIZE are not 4-KByte aligned or size is 0

THEN return INVALID; 

FI;

IF (BASE + SIZE) wrap 4-GByte address space

THEN return INVALID; 

FI;

IF TYPE is invalid for Pentium 4, Intel Xeon, and P6 family

processors

THEN return UNSUPPORTED; 

FI;

IF TYPE is WC and not supported

THEN return UNSUPPORTED; 

FI;

IF IA32_MTRRCAP.FIX is set AND range can be mapped using a

fixed-range MTRR

THEN

pre_mtrr_change();

update affected MTRR;

post_mtrr_change();

FI;

ELSE (* try to map using a variable MTRR pair *)

IF IA32_MTRRCAP.VCNT = 0

THEN return UNSUPPORTED; 

FI;

IF conflicts with current variable ranges 

THEN return RANGE_OVERLAP;

FI;

IF no MTRRs available

THEN return VAR_NOT_AVAILABLE; 

FI;

IF BASE and SIZE do not meet the power of 2 requirements for

variable MTRRs

THEN return INVALID_VAR_REQUEST; 

FI;

pre_mtrr_change();

Update affected MTRRs;

post_mtrr_change();

FI;

pre_mtrr_change()

BEGIN

disable interrupts;

Save current value of CR4;

disable and flush caches;