]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Include/Library/MtrrLib.h
Update so Windows build works like Cygwin buid
[mirror_edk2.git] / UefiCpuPkg / Include / Library / MtrrLib.h
CommitLineData
e50466da 1/** @file\r
2 MTRR setting library\r
3\r
759f21f1 4 Copyright (c) 2008 - 2010, Intel Corporation\r
e50466da 5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef _MTRR_LIB_H_\r
16#define _MTRR_LIB_H_\r
17\r
18//\r
19// According to IA32 SDM, MTRRs number and msr offset are always consistent\r
20// for IA32 processor family\r
21//\r
3b9be416
JY
22\r
23//\r
24// We can not use Pcd as macro to define structure, so we have to define MAX_MTRR_NUMBER_OF_VARIABLE_MTRR\r
25//\r
26#define MAX_MTRR_NUMBER_OF_VARIABLE_MTRR 32\r
27//\r
28// Firmware need reserve 2 MTRR for OS\r
29//\r
30#define RESERVED_FIRMWARE_VARIABLE_MTRR_NUMBER 2\r
31\r
e50466da 32#define MTRR_NUMBER_OF_FIXED_MTRR 11\r
3b9be416
JY
33#define MTRR_LIB_IA32_MTRR_CAP 0x0FE\r
34#define MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK 0x0FF\r
e50466da 35#define MTRR_LIB_IA32_MTRR_FIX64K_00000 0x250\r
36#define MTRR_LIB_IA32_MTRR_FIX16K_80000 0x258\r
37#define MTRR_LIB_IA32_MTRR_FIX16K_A0000 0x259\r
38#define MTRR_LIB_IA32_MTRR_FIX4K_C0000 0x268\r
39#define MTRR_LIB_IA32_MTRR_FIX4K_C8000 0x269\r
40#define MTRR_LIB_IA32_MTRR_FIX4K_D0000 0x26A\r
41#define MTRR_LIB_IA32_MTRR_FIX4K_D8000 0x26B\r
42#define MTRR_LIB_IA32_MTRR_FIX4K_E0000 0x26C\r
43#define MTRR_LIB_IA32_MTRR_FIX4K_E8000 0x26D\r
44#define MTRR_LIB_IA32_MTRR_FIX4K_F0000 0x26E\r
45#define MTRR_LIB_IA32_MTRR_FIX4K_F8000 0x26F\r
46#define MTRR_LIB_IA32_VARIABLE_MTRR_BASE 0x200\r
e50466da 47#define MTRR_LIB_IA32_MTRR_DEF_TYPE 0x2FF\r
48#define MTRR_LIB_MSR_VALID_MASK 0xFFFFFFFFFULL\r
49#define MTRR_LIB_CACHE_VALID_ADDRESS 0xFFFFFF000ULL\r
50#define MTRR_LIB_CACHE_MTRR_ENABLED 0x800\r
51#define MTRR_LIB_CACHE_FIXED_MTRR_ENABLED 0x400\r
52\r
53//\r
54// Structure to describe a fixed MTRR\r
55//\r
56typedef struct {\r
57 UINT32 Msr;\r
58 UINT32 BaseAddress;\r
59 UINT32 Length;\r
60} FIXED_MTRR;\r
61\r
62//\r
63// Structure to describe a variable MTRR\r
64//\r
65typedef struct {\r
66 UINT64 BaseAddress;\r
67 UINT64 Length;\r
68 UINT64 Type;\r
69 UINT32 Msr;\r
70 BOOLEAN Valid;\r
71 BOOLEAN Used;\r
72} VARIABLE_MTRR;\r
73\r
74//\r
75// Structure to hold base and mask pair for variable MTRR register\r
76//\r
77typedef struct _MTRR_VARIABLE_SETTING_ {\r
78 UINT64 Base;\r
79 UINT64 Mask;\r
80} MTRR_VARIABLE_SETTING;\r
81\r
82//\r
83// Array for variable MTRRs\r
84//\r
85typedef struct _MTRR_VARIABLE_SETTINGS_ {\r
3b9be416 86 MTRR_VARIABLE_SETTING Mtrr[MAX_MTRR_NUMBER_OF_VARIABLE_MTRR];\r
e50466da 87} MTRR_VARIABLE_SETTINGS;\r
88\r
89//\r
90// Array for fixed mtrrs\r
91//\r
92typedef struct _MTRR_FIXED_SETTINGS_ {\r
93 UINT64 Mtrr[MTRR_NUMBER_OF_FIXED_MTRR];\r
94} MTRR_FIXED_SETTINGS;\r
95\r
96//\r
97// Structure to hold all MTRRs\r
98//\r
99typedef struct _MTRR_SETTINGS_ {\r
100 MTRR_FIXED_SETTINGS Fixed;\r
101 MTRR_VARIABLE_SETTINGS Variables;\r
102 UINT64 MtrrDefType;\r
103} MTRR_SETTINGS;\r
104\r
105//\r
106// Memory cache types\r
107//\r
108typedef enum {\r
109 CacheUncacheable = 0,\r
110 CacheWriteCombining = 1,\r
111 CacheWriteThrough = 4,\r
112 CacheWriteProtected = 5,\r
113 CacheWriteBack = 6\r
114} MTRR_MEMORY_CACHE_TYPE;\r
115\r
116#define MTRR_CACHE_UNCACHEABLE 0\r
117#define MTRR_CACHE_WRITE_COMBINING 1\r
118#define MTRR_CACHE_WRITE_THROUGH 4\r
119#define MTRR_CACHE_WRITE_PROTECTED 5\r
120#define MTRR_CACHE_WRITE_BACK 6\r
121#define MTRR_CACHE_INVALID_TYPE 7\r
122\r
3b9be416
JY
123/**\r
124 Returns the variable MTRR count for the CPU.\r
125\r
126 @return Variable MTRR count\r
127\r
128**/\r
129UINT32\r
130GetVariableMtrrCount (\r
131 VOID\r
132 );\r
133\r
134/**\r
135 Returns the firmware usable variable MTRR count for the CPU.\r
136\r
137 @return Firmware usable variable MTRR count\r
138\r
139**/\r
140UINT32\r
141GetFirmwareVariableMtrrCount (\r
142 VOID\r
143 );\r
144\r
e50466da 145/**\r
146 This function attempts to set the attributes for a memory range.\r
147\r
148 @param BaseAddress The physical address that is the start address of a memory region.\r
149 @param Length The size in bytes of the memory region.\r
150 @param Attributes The bit mask of attributes to set for the memory region.\r
151\r
152 @retval RETURN_SUCCESS The attributes were set for the memory region.\r
153 @retval RETURN_INVALID_PARAMETER Length is zero.\r
154 @retval RETURN_UNSUPPORTED The processor does not support one or more bytes of the\r
155 memory resource range specified by BaseAddress and Length.\r
156 @retval RETURN_UNSUPPORTED The bit mask of attributes is not support for the memory resource\r
157 range specified by BaseAddress and Length.\r
158 @retval RETURN_ACCESS_DENIED The attributes for the memory resource range specified by\r
159 BaseAddress and Length cannot be modified.\r
160 @retval RETURN_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r
161 the memory resource range.\r
162\r
163**/\r
164RETURN_STATUS\r
165EFIAPI\r
166MtrrSetMemoryAttribute (\r
167 IN PHYSICAL_ADDRESS BaseAddress,\r
168 IN UINT64 Length,\r
169 IN MTRR_MEMORY_CACHE_TYPE Attribute\r
170 );\r
171\r
172\r
173/**\r
174 This function will get the memory cache type of the specific address.\r
175 This function is mainly for debugging purposes.\r
176\r
177 @param Address The specific address\r
178\r
179 @return The memory cache type of the specific address\r
180\r
181**/\r
182MTRR_MEMORY_CACHE_TYPE\r
183EFIAPI\r
184MtrrGetMemoryAttribute (\r
185 IN PHYSICAL_ADDRESS Address\r
186 );\r
187\r
188\r
189/**\r
190 This function will get the raw value in variable MTRRs\r
191\r
192 @param VariableSettings A buffer to hold variable MTRRs content.\r
193\r
194 @return The buffer point to MTRR_VARIABLE_SETTINGS in which holds the content of the variable mtrr\r
195\r
196**/\r
197MTRR_VARIABLE_SETTINGS*\r
198EFIAPI\r
199MtrrGetVariableMtrr (\r
200 OUT MTRR_VARIABLE_SETTINGS *VariableSettings\r
201 );\r
202\r
203\r
204/**\r
205 This function sets fixed MTRRs\r
206\r
207 @param VariableSettings A buffer to hold variable MTRRs content.\r
208\r
209 @return The pointer of VariableSettings\r
210\r
211**/\r
212MTRR_VARIABLE_SETTINGS*\r
213EFIAPI\r
214MtrrSetVariableMtrr (\r
215 IN MTRR_VARIABLE_SETTINGS *VariableSettings\r
216 );\r
217\r
218\r
219/**\r
220 This function gets the content in fixed MTRRs\r
221\r
222 @param FixedSettings A buffer to hold fixed MTRRs content.\r
223\r
224 @return The pointer of FixedSettings\r
225\r
226**/\r
227MTRR_FIXED_SETTINGS*\r
228EFIAPI\r
229MtrrGetFixedMtrr (\r
230 OUT MTRR_FIXED_SETTINGS *FixedSettings\r
231 );\r
232\r
233\r
234/**\r
235 This function sets fixed MTRRs\r
236\r
237 @param FixedSettings A buffer holding fixed MTRRs content.\r
238\r
239 @return The pointer of FixedSettings\r
240\r
241**/\r
242MTRR_FIXED_SETTINGS*\r
243EFIAPI\r
244MtrrSetFixedMtrr (\r
245 IN MTRR_FIXED_SETTINGS *FixedSettings\r
246 );\r
247\r
248\r
249/**\r
250 This function gets the content in all MTRRs (variable and fixed)\r
251\r
252 @param MtrrSetting A buffer to hold all MTRRs content.\r
253\r
254 @return The pointer of MtrrSetting\r
255\r
256**/\r
257MTRR_SETTINGS *\r
258EFIAPI\r
259MtrrGetAllMtrrs (\r
260 OUT MTRR_SETTINGS *MtrrSetting\r
261 );\r
262\r
263\r
264/**\r
265 This function sets all MTRRs (variable and fixed)\r
266\r
267 @param MtrrSetting A buffer to hold all MTRRs content.\r
268\r
269 @return The pointer of MtrrSetting\r
270\r
271**/\r
272MTRR_SETTINGS *\r
273EFIAPI\r
274MtrrSetAllMtrrs (\r
275 IN MTRR_SETTINGS *MtrrSetting\r
276 );\r
277\r
278\r
279/**\r
280 Get the attribute of variable MTRRs.\r
281\r
282 This function shadows the content of variable MTRRs into\r
283 an internal array: VariableMtrr\r
284\r
3b9be416
JY
285 @param MtrrValidBitsMask The mask for the valid bit of the MTRR\r
286 @param MtrrValidAddressMask The valid address mask for MTRR since the base address in\r
287 MTRR must align to 4K, so valid address mask equal to\r
288 MtrrValidBitsMask & 0xfffffffffffff000ULL\r
289 @param VariableMtrrCount On input, it means the array number of variable MTRRs passed in.\r
290 On output, it means the number of MTRRs which has been used if EFI_SUCCESS,\r
291 or the number of MTRR required if BUFFER_TOO_SMALL.\r
292 @param VariableMtrr The array to shadow variable MTRRs content\r
293\r
294 @retval RETURN_SUCCESS The variable MTRRs are returned.\r
295 @retval RETURN_BUFFER_TOO_SMALL The input buffer is too small to hold the variable MTRRs.\r
296\r
e50466da 297**/\r
3b9be416 298RETURN_STATUS\r
e50466da 299EFIAPI\r
300MtrrGetMemoryAttributeInVariableMtrr (\r
301 IN UINT64 MtrrValidBitsMask,\r
302 IN UINT64 MtrrValidAddressMask,\r
3b9be416 303 IN OUT UINT32 *VariableMtrrCount,\r
e50466da 304 OUT VARIABLE_MTRR *VariableMtrr\r
305 );\r
306\r
307\r
308/**\r
309 This function prints all MTRRs for debugging.\r
310**/\r
311VOID\r
312MtrrDebugPrintAllMtrrs (\r
313 );\r
314\r
315#endif // _MTRR_LIB_H_\r