7 mtrr maintenance programming interface, 1 memtypeget() function – Intel IA-32 User Manual
Page 476
10-36 Vol. 3A
MEMORY CACHE CONTROL
10.11.7 MTRR Maintenance Programming Interface
The operating system maintains the MTRRs after booting and sets up or changes the memory
types for memory-mapped devices. The operating system should provide a driver and applica-
tion programming interface (API) to access and set the MTRRs. The function calls
MemTypeGet() and MemTypeSet() define this interface.
10.11.7.1
MemTypeGet() Function
The MemTypeGet() function returns the memory type of the physical memory range specified
by the parameters base and size. The base address is the starting physical address and the size is
the number of bytes for the memory range. The function automatically aligns the base address
and size to 4-KByte boundaries. Pseudocode for the MemTypeGet() function is given in
Example 10-16.
Example 10-16. MemTypeGet() Pseudocode
#define MIXED_TYPES -1 /* 0 < MIXED_TYPES || MIXED_TYPES > 256 */
IF CPU_FEATURES.MTRR /* processor supports MTRRs */
THEN
Align BASE and SIZE to 4-KByte boundary;
IF (BASE + SIZE) wrap 4-GByte address space
THEN return INVALID;
FI;
IF MTRRdefType.E = 0
THEN return UC;
FI;
FirstType
←
Get4KMemType (BASE);
/* Obtains memory type for first 4-KByte range. */
/* See Get4KMemType (4KByteRange) in Example 10-17. */
FOR each additional 4-KByte range specified in SIZE
NextType
←
Get4KMemType (4KByteRange);
IF NextType
≠
FirstType
THEN return MixedTypes;
FI;
ROF;
return FirstType;
ELSE return UNSUPPORTED;
FI;
If the processor does not support MTRRs, the function returns UNSUPPORTED. If the MTRRs
are not enabled, then the UC memory type is returned. If more than one memory type corre-
sponds to the specified range, a status of MIXED_TYPES is returned. Otherwise, the memory
type defined for the range (UC, WC, WT, WB, or WP) is returned.