Intel 64 and IA-32 Architectures Software Developers Manual Volume 3A, System Programming Guide, Part 1

Vol. 3A 10-39
MEMORY CACHE CONTROL
3. A memory type that views write data as not necessarily stored and read back by
a subsequent read, such as the write-protected type, can only be mapped to
another type with the same behaviour (and there are no others for the
Pentium 4, Intel Xeon, and P6 family processors) or to the uncacheable type.
In many specific cases, a system designer can have additional information about how
a memory type is used, allowing additional mappings. For example, write-through
memory with no associated write side effects can be mapped into write-back
memory.
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 application 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-4.
Example 10-4. 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-5. */
FOR each additional 4-KByte range specified in SIZE
NextType
¨ Get4KMemType (4KByteRange);
IF NextType
¼ FirstType
THEN return MixedTypes;