]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Include/Library/MtrrLib.h
Enhanced TerminalDxe module not to install Simple Text(ex) input protocol and Simple...
[mirror_edk2.git] / UefiCpuPkg / Include / Library / MtrrLib.h
CommitLineData
e50466da 1/** @file\r
2 MTRR setting library\r
3\r
4 Copyright (c) 2008 - 2009, Intel Corporation\r
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
22#define MTRR_NUMBER_OF_VARIABLE_MTRR 8\r
23#define MTRR_NUMBER_OF_FIXED_MTRR 11\r
24#define FIRMWARE_VARIABLE_MTRR_NUMBER 6\r
25#define MTRR_LIB_IA32_MTRR_FIX64K_00000 0x250\r
26#define MTRR_LIB_IA32_MTRR_FIX16K_80000 0x258\r
27#define MTRR_LIB_IA32_MTRR_FIX16K_A0000 0x259\r
28#define MTRR_LIB_IA32_MTRR_FIX4K_C0000 0x268\r
29#define MTRR_LIB_IA32_MTRR_FIX4K_C8000 0x269\r
30#define MTRR_LIB_IA32_MTRR_FIX4K_D0000 0x26A\r
31#define MTRR_LIB_IA32_MTRR_FIX4K_D8000 0x26B\r
32#define MTRR_LIB_IA32_MTRR_FIX4K_E0000 0x26C\r
33#define MTRR_LIB_IA32_MTRR_FIX4K_E8000 0x26D\r
34#define MTRR_LIB_IA32_MTRR_FIX4K_F0000 0x26E\r
35#define MTRR_LIB_IA32_MTRR_FIX4K_F8000 0x26F\r
36#define MTRR_LIB_IA32_VARIABLE_MTRR_BASE 0x200\r
37#define MTRR_LIB_IA32_VARIABLE_MTRR_END 0x20F\r
38#define MTRR_LIB_IA32_MTRR_DEF_TYPE 0x2FF\r
39#define MTRR_LIB_MSR_VALID_MASK 0xFFFFFFFFFULL\r
40#define MTRR_LIB_CACHE_VALID_ADDRESS 0xFFFFFF000ULL\r
41#define MTRR_LIB_CACHE_MTRR_ENABLED 0x800\r
42#define MTRR_LIB_CACHE_FIXED_MTRR_ENABLED 0x400\r
43\r
44//\r
45// Structure to describe a fixed MTRR\r
46//\r
47typedef struct {\r
48 UINT32 Msr;\r
49 UINT32 BaseAddress;\r
50 UINT32 Length;\r
51} FIXED_MTRR;\r
52\r
53//\r
54// Structure to describe a variable MTRR\r
55//\r
56typedef struct {\r
57 UINT64 BaseAddress;\r
58 UINT64 Length;\r
59 UINT64 Type;\r
60 UINT32 Msr;\r
61 BOOLEAN Valid;\r
62 BOOLEAN Used;\r
63} VARIABLE_MTRR;\r
64\r
65//\r
66// Structure to hold base and mask pair for variable MTRR register\r
67//\r
68typedef struct _MTRR_VARIABLE_SETTING_ {\r
69 UINT64 Base;\r
70 UINT64 Mask;\r
71} MTRR_VARIABLE_SETTING;\r
72\r
73//\r
74// Array for variable MTRRs\r
75//\r
76typedef struct _MTRR_VARIABLE_SETTINGS_ {\r
77 MTRR_VARIABLE_SETTING Mtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];\r
78} MTRR_VARIABLE_SETTINGS;\r
79\r
80//\r
81// Array for fixed mtrrs\r
82//\r
83typedef struct _MTRR_FIXED_SETTINGS_ {\r
84 UINT64 Mtrr[MTRR_NUMBER_OF_FIXED_MTRR];\r
85} MTRR_FIXED_SETTINGS;\r
86\r
87//\r
88// Structure to hold all MTRRs\r
89//\r
90typedef struct _MTRR_SETTINGS_ {\r
91 MTRR_FIXED_SETTINGS Fixed;\r
92 MTRR_VARIABLE_SETTINGS Variables;\r
93 UINT64 MtrrDefType;\r
94} MTRR_SETTINGS;\r
95\r
96//\r
97// Memory cache types\r
98//\r
99typedef enum {\r
100 CacheUncacheable = 0,\r
101 CacheWriteCombining = 1,\r
102 CacheWriteThrough = 4,\r
103 CacheWriteProtected = 5,\r
104 CacheWriteBack = 6\r
105} MTRR_MEMORY_CACHE_TYPE;\r
106\r
107#define MTRR_CACHE_UNCACHEABLE 0\r
108#define MTRR_CACHE_WRITE_COMBINING 1\r
109#define MTRR_CACHE_WRITE_THROUGH 4\r
110#define MTRR_CACHE_WRITE_PROTECTED 5\r
111#define MTRR_CACHE_WRITE_BACK 6\r
112#define MTRR_CACHE_INVALID_TYPE 7\r
113\r
114//\r
115// structure for memory attribute descriptor according MTRR setting\r
116//\r
117typedef struct _MTRR_MEMORY_ATTRIBUTE_MAP_ {\r
118 PHYSICAL_ADDRESS StartAddress;\r
119 PHYSICAL_ADDRESS EndAddress;\r
120 MTRR_MEMORY_CACHE_TYPE Attribute;\r
121} MTRR_MEMORY_ATTRIBUTE_MAP;\r
122\r
123\r
124/**\r
125 This function attempts to set the attributes for a memory range.\r
126\r
127 @param BaseAddress The physical address that is the start address of a memory region.\r
128 @param Length The size in bytes of the memory region.\r
129 @param Attributes The bit mask of attributes to set for the memory region.\r
130\r
131 @retval RETURN_SUCCESS The attributes were set for the memory region.\r
132 @retval RETURN_INVALID_PARAMETER Length is zero.\r
133 @retval RETURN_UNSUPPORTED The processor does not support one or more bytes of the\r
134 memory resource range specified by BaseAddress and Length.\r
135 @retval RETURN_UNSUPPORTED The bit mask of attributes is not support for the memory resource\r
136 range specified by BaseAddress and Length.\r
137 @retval RETURN_ACCESS_DENIED The attributes for the memory resource range specified by\r
138 BaseAddress and Length cannot be modified.\r
139 @retval RETURN_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r
140 the memory resource range.\r
141\r
142**/\r
143RETURN_STATUS\r
144EFIAPI\r
145MtrrSetMemoryAttribute (\r
146 IN PHYSICAL_ADDRESS BaseAddress,\r
147 IN UINT64 Length,\r
148 IN MTRR_MEMORY_CACHE_TYPE Attribute\r
149 );\r
150\r
151\r
152/**\r
153 This function will get the memory cache type of the specific address.\r
154 This function is mainly for debugging purposes.\r
155\r
156 @param Address The specific address\r
157\r
158 @return The memory cache type of the specific address\r
159\r
160**/\r
161MTRR_MEMORY_CACHE_TYPE\r
162EFIAPI\r
163MtrrGetMemoryAttribute (\r
164 IN PHYSICAL_ADDRESS Address\r
165 );\r
166\r
167\r
168/**\r
169 This function will get the raw value in variable MTRRs\r
170\r
171 @param VariableSettings A buffer to hold variable MTRRs content.\r
172\r
173 @return The buffer point to MTRR_VARIABLE_SETTINGS in which holds the content of the variable mtrr\r
174\r
175**/\r
176MTRR_VARIABLE_SETTINGS*\r
177EFIAPI\r
178MtrrGetVariableMtrr (\r
179 OUT MTRR_VARIABLE_SETTINGS *VariableSettings\r
180 );\r
181\r
182\r
183/**\r
184 This function sets fixed MTRRs\r
185\r
186 @param VariableSettings A buffer to hold variable MTRRs content.\r
187\r
188 @return The pointer of VariableSettings\r
189\r
190**/\r
191MTRR_VARIABLE_SETTINGS*\r
192EFIAPI\r
193MtrrSetVariableMtrr (\r
194 IN MTRR_VARIABLE_SETTINGS *VariableSettings\r
195 );\r
196\r
197\r
198/**\r
199 This function gets the content in fixed MTRRs\r
200\r
201 @param FixedSettings A buffer to hold fixed MTRRs content.\r
202\r
203 @return The pointer of FixedSettings\r
204\r
205**/\r
206MTRR_FIXED_SETTINGS*\r
207EFIAPI\r
208MtrrGetFixedMtrr (\r
209 OUT MTRR_FIXED_SETTINGS *FixedSettings\r
210 );\r
211\r
212\r
213/**\r
214 This function sets fixed MTRRs\r
215\r
216 @param FixedSettings A buffer holding fixed MTRRs content.\r
217\r
218 @return The pointer of FixedSettings\r
219\r
220**/\r
221MTRR_FIXED_SETTINGS*\r
222EFIAPI\r
223MtrrSetFixedMtrr (\r
224 IN MTRR_FIXED_SETTINGS *FixedSettings\r
225 );\r
226\r
227\r
228/**\r
229 This function gets the content in all MTRRs (variable and fixed)\r
230\r
231 @param MtrrSetting A buffer to hold all MTRRs content.\r
232\r
233 @return The pointer of MtrrSetting\r
234\r
235**/\r
236MTRR_SETTINGS *\r
237EFIAPI\r
238MtrrGetAllMtrrs (\r
239 OUT MTRR_SETTINGS *MtrrSetting\r
240 );\r
241\r
242\r
243/**\r
244 This function sets all MTRRs (variable and fixed)\r
245\r
246 @param MtrrSetting A buffer to hold all MTRRs content.\r
247\r
248 @return The pointer of MtrrSetting\r
249\r
250**/\r
251MTRR_SETTINGS *\r
252EFIAPI\r
253MtrrSetAllMtrrs (\r
254 IN MTRR_SETTINGS *MtrrSetting\r
255 );\r
256\r
257\r
258/**\r
259 Get the attribute of variable MTRRs.\r
260\r
261 This function shadows the content of variable MTRRs into\r
262 an internal array: VariableMtrr\r
263\r
264 @param MtrrValidBitsMask The mask for the valid bit of the MTRR\r
265 @param MtrrValidAddressMask The valid address mask for MTRR since the base address in\r
266 MTRR must align to 4K, so valid address mask equal to\r
267 MtrrValidBitsMask & 0xfffffffffffff000ULL\r
268 @param VariableMtrr The array to shadow variable MTRRs content\r
269 @return The ruturn value of this paramter indicates the number of\r
270 MTRRs which has been used.\r
271**/\r
272UINT32\r
273EFIAPI\r
274MtrrGetMemoryAttributeInVariableMtrr (\r
275 IN UINT64 MtrrValidBitsMask,\r
276 IN UINT64 MtrrValidAddressMask,\r
277 OUT VARIABLE_MTRR *VariableMtrr\r
278 );\r
279\r
280\r
281/**\r
282 This function prints all MTRRs for debugging.\r
283**/\r
284VOID\r
285MtrrDebugPrintAllMtrrs (\r
286 );\r
287\r
288#endif // _MTRR_LIB_H_\r