TianoCore EDK2 master
Loading...
Searching...
No Matches
MtrrLib.h
Go to the documentation of this file.
1
9#ifndef _MTRR_LIB_H_
10#define _MTRR_LIB_H_
11
13
14//
15// According to IA32 SDM, MTRRs number and MSR offset are always consistent
16// for IA32 processor family
17//
18
19//
20// The semantics of below macro is MAX_MTRR_NUMBER_OF_VARIABLE_MTRR, the real number can be read out from MTRR_CAP register.
21//
22#define MTRR_NUMBER_OF_VARIABLE_MTRR 32
23//
24// Firmware need reserve 2 MTRR for OS
25// Note: It is replaced by PCD PcdCpuNumberOfReservedVariableMtrrs
26//
27#define RESERVED_FIRMWARE_VARIABLE_MTRR_NUMBER 2
28
29#define MTRR_NUMBER_OF_FIXED_MTRR 11
30
31//
32// Structure to describe a fixed MTRR
33//
34typedef struct {
35 UINT32 Msr;
36 UINT32 BaseAddress;
37 UINT32 Length;
39
40//
41// Structure to describe a variable MTRR
42//
43typedef struct {
44 UINT64 BaseAddress;
45 UINT64 Length;
46 UINT64 Type;
47 UINT32 Msr;
48 BOOLEAN Valid;
49 BOOLEAN Used;
51
52//
53// Structure to hold base and mask pair for variable MTRR register
54//
56 UINT64 Base;
57 UINT64 Mask;
59
60//
61// Array for variable MTRRs
62//
64 MTRR_VARIABLE_SETTING Mtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];
66
67//
68// Array for fixed MTRRs
69//
70typedef struct _MTRR_FIXED_SETTINGS_ {
71 UINT64 Mtrr[MTRR_NUMBER_OF_FIXED_MTRR];
73
74//
75// Structure to hold all MTRRs
76//
77typedef struct _MTRR_SETTINGS_ {
79 MTRR_VARIABLE_SETTINGS Variables;
80 UINT64 MtrrDefType;
82
83//
84// Memory cache types
85//
86typedef enum {
87 CacheUncacheable = MSR_IA32_MTRR_CACHE_UNCACHEABLE,
88 CacheWriteCombining = MSR_IA32_MTRR_CACHE_WRITE_COMBINING,
89 CacheWriteThrough = MSR_IA32_MTRR_CACHE_WRITE_THROUGH,
90 CacheWriteProtected = MSR_IA32_MTRR_CACHE_WRITE_PROTECTED,
91 CacheWriteBack = MSR_IA32_MTRR_CACHE_WRITE_BACK,
92 CacheInvalid = MSR_IA32_MTRR_CACHE_INVALID_TYPE,
93} MTRR_MEMORY_CACHE_TYPE;
94
95#define MTRR_CACHE_UNCACHEABLE MSR_IA32_MTRR_CACHE_UNCACHEABLE
96#define MTRR_CACHE_WRITE_COMBINING MSR_IA32_MTRR_CACHE_WRITE_COMBINING
97#define MTRR_CACHE_WRITE_THROUGH MSR_IA32_MTRR_CACHE_WRITE_THROUGH
98#define MTRR_CACHE_WRITE_PROTECTED MSR_IA32_MTRR_CACHE_WRITE_PROTECTED
99#define MTRR_CACHE_WRITE_BACK MSR_IA32_MTRR_CACHE_WRITE_BACK
100#define MTRR_CACHE_INVALID_TYPE MSR_IA32_MTRR_CACHE_INVALID_TYPE
101
102typedef struct {
103 UINT64 BaseAddress;
104 UINT64 Length;
105 MTRR_MEMORY_CACHE_TYPE Type;
107
114UINT32
115EFIAPI
117 VOID
118 );
119
126UINT32
127EFIAPI
129 VOID
130 );
131
165RETURN_STATUS
166EFIAPI
168 IN PHYSICAL_ADDRESS BaseAddress,
169 IN UINT64 Length,
170 IN MTRR_MEMORY_CACHE_TYPE Attribute
171 );
172
182MTRR_MEMORY_CACHE_TYPE
183EFIAPI
185 IN PHYSICAL_ADDRESS Address
186 );
187
197EFIAPI
199 OUT MTRR_FIXED_SETTINGS *FixedSettings
200 );
201
211EFIAPI
213 OUT MTRR_SETTINGS *MtrrSetting
214 );
215
228EFIAPI
230 IN MTRR_SETTINGS *MtrrSetting
231 );
232
248UINT32
249EFIAPI
251 IN UINT64 MtrrValidBitsMask,
252 IN UINT64 MtrrValidAddressMask,
253 OUT VARIABLE_MTRR *VariableMtrr
254 );
255
259VOID
260EFIAPI
262 VOID
263 );
264
272BOOLEAN
273EFIAPI
275 VOID
276 );
277
284MTRR_MEMORY_CACHE_TYPE
285EFIAPI
287 VOID
288 );
289
319RETURN_STATUS
320EFIAPI
322 IN OUT MTRR_SETTINGS *MtrrSetting,
323 IN PHYSICAL_ADDRESS BaseAddress,
324 IN UINT64 Length,
325 IN MTRR_MEMORY_CACHE_TYPE Attribute
326 );
327
354RETURN_STATUS
355EFIAPI
357 IN OUT MTRR_SETTINGS *MtrrSetting,
358 IN VOID *Scratch,
359 IN OUT UINTN *ScratchSize,
360 IN CONST MTRR_MEMORY_RANGE *Ranges,
361 IN UINTN RangeCount
362 );
363
379RETURN_STATUS
380EFIAPI
382 IN CONST MTRR_SETTINGS *MtrrSetting OPTIONAL,
383 OUT MTRR_MEMORY_RANGE *Ranges,
384 IN OUT UINTN *RangeCount
385 );
386
387#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:740
MTRR_MEMORY_CACHE_TYPE EFIAPI MtrrGetMemoryAttribute(IN PHYSICAL_ADDRESS Address)
Definition: MtrrLib.c:1021
VOID EFIAPI MtrrDebugPrintAllMtrrs(VOID)
Definition: MtrrLib.c:3161
MTRR_SETTINGS *EFIAPI MtrrSetAllMtrrs(IN MTRR_SETTINGS *MtrrSetting)
Definition: MtrrLib.c:2908
RETURN_STATUS EFIAPI MtrrGetMemoryAttributesInMtrrSettings(IN CONST MTRR_SETTINGS *MtrrSetting OPTIONAL, OUT MTRR_MEMORY_RANGE *Ranges, IN OUT UINTN *RangeCount)
Definition: MtrrLib.c:2984
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:2729
UINT32 EFIAPI GetVariableMtrrCount(VOID)
Definition: MtrrLib.c:235
UINT32 EFIAPI GetFirmwareVariableMtrrCount(VOID)
Definition: MtrrLib.c:277
BOOLEAN EFIAPI IsMtrrSupported(VOID)
Definition: MtrrLib.c:2960
RETURN_STATUS EFIAPI MtrrSetMemoryAttribute(IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN MTRR_MEMORY_CACHE_TYPE Attribute)
Definition: MtrrLib.c:2782
MTRR_FIXED_SETTINGS *EFIAPI MtrrGetFixedMtrr(OUT MTRR_FIXED_SETTINGS *FixedSettings)
Definition: MtrrLib.c:474
MTRR_MEMORY_CACHE_TYPE EFIAPI MtrrGetDefaultMemoryType(VOID)
Definition: MtrrLib.c:324
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:2336
MTRR_SETTINGS *EFIAPI MtrrGetAllMtrrs(OUT MTRR_SETTINGS *MtrrSetting)
Definition: MtrrLib.c:2851