TianoCore EDK2 master
MtrrLib.h
Go to the documentation of this file.
1
9#ifndef _MTRR_LIB_H_
10#define _MTRR_LIB_H_
11
12//
13// According to IA32 SDM, MTRRs number and MSR offset are always consistent
14// for IA32 processor family
15//
16
17//
18// The semantics of below macro is MAX_MTRR_NUMBER_OF_VARIABLE_MTRR, the real number can be read out from MTRR_CAP register.
19//
20#define MTRR_NUMBER_OF_VARIABLE_MTRR 32
21//
22// Firmware need reserve 2 MTRR for OS
23// Note: It is replaced by PCD PcdCpuNumberOfReservedVariableMtrrs
24//
25#define RESERVED_FIRMWARE_VARIABLE_MTRR_NUMBER 2
26
27#define MTRR_NUMBER_OF_FIXED_MTRR 11
28
29//
30// Structure to describe a fixed MTRR
31//
32typedef struct {
33 UINT32 Msr;
34 UINT32 BaseAddress;
35 UINT32 Length;
37
38//
39// Structure to describe a variable MTRR
40//
41typedef struct {
42 UINT64 BaseAddress;
43 UINT64 Length;
44 UINT64 Type;
45 UINT32 Msr;
46 BOOLEAN Valid;
47 BOOLEAN Used;
49
50//
51// Structure to hold base and mask pair for variable MTRR register
52//
54 UINT64 Base;
55 UINT64 Mask;
57
58//
59// Array for variable MTRRs
60//
62 MTRR_VARIABLE_SETTING Mtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];
64
65//
66// Array for fixed MTRRs
67//
68typedef struct _MTRR_FIXED_SETTINGS_ {
69 UINT64 Mtrr[MTRR_NUMBER_OF_FIXED_MTRR];
71
72//
73// Structure to hold all MTRRs
74//
75typedef struct _MTRR_SETTINGS_ {
77 MTRR_VARIABLE_SETTINGS Variables;
78 UINT64 MtrrDefType;
80
81//
82// Memory cache types
83//
84typedef enum {
85 CacheUncacheable = 0,
86 CacheWriteCombining = 1,
87 CacheWriteThrough = 4,
88 CacheWriteProtected = 5,
89 CacheWriteBack = 6,
90 CacheInvalid = 7
91} MTRR_MEMORY_CACHE_TYPE;
92
93#define MTRR_CACHE_UNCACHEABLE 0
94#define MTRR_CACHE_WRITE_COMBINING 1
95#define MTRR_CACHE_WRITE_THROUGH 4
96#define MTRR_CACHE_WRITE_PROTECTED 5
97#define MTRR_CACHE_WRITE_BACK 6
98#define MTRR_CACHE_INVALID_TYPE 7
99
100typedef struct {
101 UINT64 BaseAddress;
102 UINT64 Length;
103 MTRR_MEMORY_CACHE_TYPE Type;
105
112UINT32
113EFIAPI
115 VOID
116 );
117
124UINT32
125EFIAPI
127 VOID
128 );
129
163RETURN_STATUS
164EFIAPI
166 IN PHYSICAL_ADDRESS BaseAddress,
167 IN UINT64 Length,
168 IN MTRR_MEMORY_CACHE_TYPE Attribute
169 );
170
180MTRR_MEMORY_CACHE_TYPE
181EFIAPI
183 IN PHYSICAL_ADDRESS Address
184 );
185
195EFIAPI
197 OUT MTRR_FIXED_SETTINGS *FixedSettings
198 );
199
209EFIAPI
211 OUT MTRR_SETTINGS *MtrrSetting
212 );
213
223EFIAPI
225 IN MTRR_SETTINGS *MtrrSetting
226 );
227
243UINT32
244EFIAPI
246 IN UINT64 MtrrValidBitsMask,
247 IN UINT64 MtrrValidAddressMask,
248 OUT VARIABLE_MTRR *VariableMtrr
249 );
250
254VOID
255EFIAPI
257 VOID
258 );
259
267BOOLEAN
268EFIAPI
270 VOID
271 );
272
279MTRR_MEMORY_CACHE_TYPE
280EFIAPI
282 VOID
283 );
284
314RETURN_STATUS
315EFIAPI
317 IN OUT MTRR_SETTINGS *MtrrSetting,
318 IN PHYSICAL_ADDRESS BaseAddress,
319 IN UINT64 Length,
320 IN MTRR_MEMORY_CACHE_TYPE Attribute
321 );
322
349RETURN_STATUS
350EFIAPI
352 IN OUT MTRR_SETTINGS *MtrrSetting,
353 IN VOID *Scratch,
354 IN OUT UINTN *ScratchSize,
355 IN CONST MTRR_MEMORY_RANGE *Ranges,
356 IN UINTN RangeCount
357 );
358
359#endif // _MTRR_LIB_H_
UINT64 UINTN
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
UINT32 EFIAPI MtrrGetMemoryAttributeInVariableMtrr(IN UINT64 MtrrValidBitsMask, IN UINT64 MtrrValidAddressMask, OUT VARIABLE_MTRR *VariableMtrr)
Definition: MtrrLib.c:671
MTRR_MEMORY_CACHE_TYPE EFIAPI MtrrGetMemoryAttribute(IN PHYSICAL_ADDRESS Address)
Definition: MtrrLib.c:932
VOID EFIAPI MtrrDebugPrintAllMtrrs(VOID)
Definition: MtrrLib.c:2991
MTRR_SETTINGS *EFIAPI MtrrSetAllMtrrs(IN MTRR_SETTINGS *MtrrSetting)
Definition: MtrrLib.c:2800
RETURN_STATUS EFIAPI MtrrSetMemoryAttributeInMtrrSettings(IN OUT MTRR_SETTINGS *MtrrSetting, IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN MTRR_MEMORY_CACHE_TYPE Attribute)
Definition: MtrrLib.c:2638
UINT32 EFIAPI GetVariableMtrrCount(VOID)
Definition: MtrrLib.c:169
UINT32 EFIAPI GetFirmwareVariableMtrrCount(VOID)
Definition: MtrrLib.c:211
BOOLEAN EFIAPI IsMtrrSupported(VOID)
Definition: MtrrLib.c:2841
RETURN_STATUS EFIAPI MtrrSetMemoryAttribute(IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN MTRR_MEMORY_CACHE_TYPE Attribute)
Definition: MtrrLib.c:2691
MTRR_FIXED_SETTINGS *EFIAPI MtrrGetFixedMtrr(OUT MTRR_FIXED_SETTINGS *FixedSettings)
Definition: MtrrLib.c:409
MTRR_MEMORY_CACHE_TYPE EFIAPI MtrrGetDefaultMemoryType(VOID)
Definition: MtrrLib.c:258
RETURN_STATUS EFIAPI MtrrSetMemoryAttributesInMtrrSettings(IN OUT MTRR_SETTINGS *MtrrSetting, IN VOID *Scratch, IN OUT UINTN *ScratchSize, IN CONST MTRR_MEMORY_RANGE *Ranges, IN UINTN RangeCount)
Definition: MtrrLib.c:2260
MTRR_SETTINGS *EFIAPI MtrrGetAllMtrrs(OUT MTRR_SETTINGS *MtrrSetting)
Definition: MtrrLib.c:2760