]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | IA-32/x64 MSR functions.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
5 | 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 | \r | |
16 | #include "BaseLibInternals.h"\r | |
17 | \r | |
18 | \r | |
19 | /**\r | |
20 | Returns the lower 32-bits of a Machine Specific Register(MSR).\r | |
21 | \r | |
22 | Reads and returns the lower 32-bits of the MSR specified by Index.\r | |
23 | No parameter checking is performed on Index, and some Index values may cause\r | |
24 | CPU exceptions. The caller must either guarantee that Index is valid, or the\r | |
25 | caller must set up exception handlers to catch the exceptions. This function\r | |
26 | is only available on IA-32 and x64.\r | |
27 | \r | |
28 | @param Index The 32-bit MSR index to read.\r | |
29 | \r | |
30 | @return The lower 32 bits of the MSR identified by Index.\r | |
31 | \r | |
32 | **/\r | |
33 | UINT32\r | |
34 | EFIAPI\r | |
35 | AsmReadMsr32 (\r | |
36 | IN UINT32 Index\r | |
37 | )\r | |
38 | {\r | |
39 | return (UINT32)AsmReadMsr64 (Index);\r | |
40 | }\r | |
41 | \r | |
42 | /**\r | |
43 | Writes a 32-bit value to a Machine Specific Register(MSR), and returns the value.\r | |
44 | The upper 32-bits of the MSR are set to zero.\r | |
45 | \r | |
46 | Writes the 32-bit value specified by Value to the MSR specified by Index. The\r | |
47 | upper 32-bits of the MSR write are set to zero. The 32-bit value written to\r | |
48 | the MSR is returned. No parameter checking is performed on Index or Value,\r | |
49 | and some of these may cause CPU exceptions. The caller must either guarantee\r | |
50 | that Index and Value are valid, or the caller must establish proper exception\r | |
51 | handlers. This function is only available on IA-32 and x64.\r | |
52 | \r | |
53 | @param Index The 32-bit MSR index to write.\r | |
54 | @param Value The 32-bit value to write to the MSR.\r | |
55 | \r | |
56 | @return Value\r | |
57 | \r | |
58 | **/\r | |
59 | UINT32\r | |
60 | EFIAPI\r | |
61 | AsmWriteMsr32 (\r | |
62 | IN UINT32 Index,\r | |
63 | IN UINT32 Value\r | |
64 | )\r | |
65 | {\r | |
66 | return (UINT32)AsmWriteMsr64 (Index, Value);\r | |
67 | }\r | |
68 | \r | |
69 | /**\r | |
70 | Reads a 64-bit MSR, performs a bitwise OR on the lower 32-bits, and\r | |
71 | writes the result back to the 64-bit MSR.\r | |
72 | \r | |
73 | Reads the 64-bit MSR specified by Index, performs a bitwise OR\r | |
74 | between the lower 32-bits of the read result and the value specified by\r | |
75 | OrData, and writes the result to the 64-bit MSR specified by Index. The lower\r | |
76 | 32-bits of the value written to the MSR is returned. No parameter checking is\r | |
77 | performed on Index or OrData, and some of these may cause CPU exceptions. The\r | |
78 | caller must either guarantee that Index and OrData are valid, or the caller\r | |
79 | must establish proper exception handlers. This function is only available on\r | |
80 | IA-32 and x64.\r | |
81 | \r | |
82 | @param Index The 32-bit MSR index to write.\r | |
83 | @param OrData The value to OR with the read value from the MSR.\r | |
84 | \r | |
85 | @return The lower 32-bit value written to the MSR.\r | |
86 | \r | |
87 | **/\r | |
88 | UINT32\r | |
89 | EFIAPI\r | |
90 | AsmMsrOr32 (\r | |
91 | IN UINT32 Index,\r | |
92 | IN UINT32 OrData\r | |
93 | )\r | |
94 | {\r | |
95 | return (UINT32)AsmMsrOr64 (Index, OrData);\r | |
96 | }\r | |
97 | \r | |
98 | /**\r | |
99 | Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes\r | |
100 | the result back to the 64-bit MSR.\r | |
101 | \r | |
102 | Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r | |
103 | lower 32-bits of the read result and the value specified by AndData, and\r | |
104 | writes the result to the 64-bit MSR specified by Index. The lower 32-bits of\r | |
105 | the value written to the MSR is returned. No parameter checking is performed\r | |
106 | on Index or AndData, and some of these may cause CPU exceptions. The caller\r | |
107 | must either guarantee that Index and AndData are valid, or the caller must\r | |
108 | establish proper exception handlers. This function is only available on IA-32\r | |
109 | and x64.\r | |
110 | \r | |
111 | @param Index The 32-bit MSR index to write.\r | |
112 | @param AndData The value to AND with the read value from the MSR.\r | |
113 | \r | |
114 | @return The lower 32-bit value written to the MSR.\r | |
115 | \r | |
116 | **/\r | |
117 | UINT32\r | |
118 | EFIAPI\r | |
119 | AsmMsrAnd32 (\r | |
120 | IN UINT32 Index,\r | |
121 | IN UINT32 AndData\r | |
122 | )\r | |
123 | {\r | |
124 | return (UINT32)AsmMsrAnd64 (Index, AndData);\r | |
125 | }\r | |
126 | \r | |
127 | /**\r | |
128 | Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise OR\r | |
129 | on the lower 32-bits, and writes the result back to the 64-bit MSR.\r | |
130 | \r | |
131 | Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r | |
132 | lower 32-bits of the read result and the value specified by AndData\r | |
133 | preserving the upper 32-bits, performs a bitwise OR between the\r | |
134 | result of the AND operation and the value specified by OrData, and writes the\r | |
135 | result to the 64-bit MSR specified by Address. The lower 32-bits of the value\r | |
136 | written to the MSR is returned. No parameter checking is performed on Index,\r | |
137 | AndData, or OrData, and some of these may cause CPU exceptions. The caller\r | |
138 | must either guarantee that Index, AndData, and OrData are valid, or the\r | |
139 | caller must establish proper exception handlers. This function is only\r | |
140 | available on IA-32 and x64.\r | |
141 | \r | |
142 | @param Index The 32-bit MSR index to write.\r | |
143 | @param AndData The value to AND with the read value from the MSR.\r | |
144 | @param OrData The value to OR with the result of the AND operation.\r | |
145 | \r | |
146 | @return The lower 32-bit value written to the MSR.\r | |
147 | \r | |
148 | **/\r | |
149 | UINT32\r | |
150 | EFIAPI\r | |
151 | AsmMsrAndThenOr32 (\r | |
152 | IN UINT32 Index,\r | |
153 | IN UINT32 AndData,\r | |
154 | IN UINT32 OrData\r | |
155 | )\r | |
156 | {\r | |
157 | return (UINT32)AsmMsrAndThenOr64 (Index, AndData, OrData);\r | |
158 | }\r | |
159 | \r | |
160 | /**\r | |
161 | Reads a bit field of an MSR.\r | |
162 | \r | |
163 | Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is\r | |
164 | specified by the StartBit and the EndBit. The value of the bit field is\r | |
165 | returned. The caller must either guarantee that Index is valid, or the caller\r | |
166 | must set up exception handlers to catch the exceptions. This function is only\r | |
167 | available on IA-32 and x64.\r | |
168 | \r | |
169 | If StartBit is greater than 31, then ASSERT().\r | |
170 | If EndBit is greater than 31, then ASSERT().\r | |
171 | If EndBit is less than StartBit, then ASSERT().\r | |
172 | \r | |
173 | @param Index The 32-bit MSR index to read.\r | |
174 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
175 | Range 0..31.\r | |
176 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
177 | Range 0..31.\r | |
178 | \r | |
179 | @return The bit field read from the MSR.\r | |
180 | \r | |
181 | **/\r | |
182 | UINT32\r | |
183 | EFIAPI\r | |
184 | AsmMsrBitFieldRead32 (\r | |
185 | IN UINT32 Index,\r | |
186 | IN UINTN StartBit,\r | |
187 | IN UINTN EndBit\r | |
188 | )\r | |
189 | {\r | |
190 | return BitFieldRead32 (AsmReadMsr32 (Index), StartBit, EndBit);\r | |
191 | }\r | |
192 | \r | |
193 | /**\r | |
194 | Writes a bit field to an MSR.\r | |
195 | \r | |
196 | Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit\r | |
197 | field is specified by the StartBit and the EndBit. All other bits in the\r | |
198 | destination MSR are preserved. The lower 32-bits of the MSR written is\r | |
199 | returned. The caller must either guarantee that Index and the data written\r | |
200 | is valid, or the caller must set up exception handlers to catch the exceptions.\r | |
201 | This function is only available on IA-32 and x64.\r | |
202 | \r | |
203 | If StartBit is greater than 31, then ASSERT().\r | |
204 | If EndBit is greater than 31, then ASSERT().\r | |
205 | If EndBit is less than StartBit, then ASSERT().\r | |
206 | If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
207 | \r | |
208 | @param Index The 32-bit MSR index to write.\r | |
209 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
210 | Range 0..31.\r | |
211 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
212 | Range 0..31.\r | |
213 | @param Value The new value of the bit field.\r | |
214 | \r | |
215 | @return The lower 32-bit of the value written to the MSR.\r | |
216 | \r | |
217 | **/\r | |
218 | UINT32\r | |
219 | EFIAPI\r | |
220 | AsmMsrBitFieldWrite32 (\r | |
221 | IN UINT32 Index,\r | |
222 | IN UINTN StartBit,\r | |
223 | IN UINTN EndBit,\r | |
224 | IN UINT32 Value\r | |
225 | )\r | |
226 | {\r | |
227 | ASSERT (EndBit < sizeof (Value) * 8);\r | |
228 | ASSERT (StartBit <= EndBit);\r | |
229 | return (UINT32)AsmMsrBitFieldWrite64 (Index, StartBit, EndBit, Value);\r | |
230 | }\r | |
231 | \r | |
232 | /**\r | |
233 | Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the\r | |
234 | result back to the bit field in the 64-bit MSR.\r | |
235 | \r | |
236 | Reads the 64-bit MSR specified by Index, performs a bitwise OR\r | |
237 | between the read result and the value specified by OrData, and writes the\r | |
238 | result to the 64-bit MSR specified by Index. The lower 32-bits of the value\r | |
239 | written to the MSR are returned. Extra left bits in OrData are stripped. The\r | |
240 | caller must either guarantee that Index and the data written is valid, or\r | |
241 | the caller must set up exception handlers to catch the exceptions. This\r | |
242 | function is only available on IA-32 and x64.\r | |
243 | \r | |
244 | If StartBit is greater than 31, then ASSERT().\r | |
245 | If EndBit is greater than 31, then ASSERT().\r | |
246 | If EndBit is less than StartBit, then ASSERT().\r | |
247 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
248 | \r | |
249 | @param Index The 32-bit MSR index to write.\r | |
250 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
251 | Range 0..31.\r | |
252 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
253 | Range 0..31.\r | |
254 | @param OrData The value to OR with the read value from the MSR.\r | |
255 | \r | |
256 | @return The lower 32-bit of the value written to the MSR.\r | |
257 | \r | |
258 | **/\r | |
259 | UINT32\r | |
260 | EFIAPI\r | |
261 | AsmMsrBitFieldOr32 (\r | |
262 | IN UINT32 Index,\r | |
263 | IN UINTN StartBit,\r | |
264 | IN UINTN EndBit,\r | |
265 | IN UINT32 OrData\r | |
266 | )\r | |
267 | {\r | |
268 | ASSERT (EndBit < sizeof (OrData) * 8);\r | |
269 | ASSERT (StartBit <= EndBit);\r | |
270 | return (UINT32)AsmMsrBitFieldOr64 (Index, StartBit, EndBit, OrData);\r | |
271 | }\r | |
272 | \r | |
273 | /**\r | |
274 | Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the\r | |
275 | result back to the bit field in the 64-bit MSR.\r | |
276 | \r | |
277 | Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r | |
278 | read result and the value specified by AndData, and writes the result to the\r | |
279 | 64-bit MSR specified by Index. The lower 32-bits of the value written to the\r | |
280 | MSR are returned. Extra left bits in AndData are stripped. The caller must\r | |
281 | either guarantee that Index and the data written is valid, or the caller must\r | |
282 | set up exception handlers to catch the exceptions. This function is only\r | |
283 | available on IA-32 and x64.\r | |
284 | \r | |
285 | If StartBit is greater than 31, then ASSERT().\r | |
286 | If EndBit is greater than 31, then ASSERT().\r | |
287 | If EndBit is less than StartBit, then ASSERT().\r | |
288 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
289 | \r | |
290 | @param Index The 32-bit MSR index to write.\r | |
291 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
292 | Range 0..31.\r | |
293 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
294 | Range 0..31.\r | |
295 | @param AndData The value to AND with the read value from the MSR.\r | |
296 | \r | |
297 | @return The lower 32-bit of the value written to the MSR.\r | |
298 | \r | |
299 | **/\r | |
300 | UINT32\r | |
301 | EFIAPI\r | |
302 | AsmMsrBitFieldAnd32 (\r | |
303 | IN UINT32 Index,\r | |
304 | IN UINTN StartBit,\r | |
305 | IN UINTN EndBit,\r | |
306 | IN UINT32 AndData\r | |
307 | )\r | |
308 | {\r | |
309 | ASSERT (EndBit < sizeof (AndData) * 8);\r | |
310 | ASSERT (StartBit <= EndBit);\r | |
311 | return (UINT32)AsmMsrBitFieldAnd64 (Index, StartBit, EndBit, AndData);\r | |
312 | }\r | |
313 | \r | |
314 | /**\r | |
315 | Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a\r | |
316 | bitwise OR, and writes the result back to the bit field in the\r | |
317 | 64-bit MSR.\r | |
318 | \r | |
319 | Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a\r | |
320 | bitwise OR between the read result and the value specified by\r | |
321 | AndData, and writes the result to the 64-bit MSR specified by Index. The\r | |
322 | lower 32-bits of the value written to the MSR are returned. Extra left bits\r | |
323 | in both AndData and OrData are stripped. The caller must either guarantee\r | |
324 | that Index and the data written is valid, or the caller must set up exception\r | |
325 | handlers to catch the exceptions. This function is only available on IA-32\r | |
326 | and x64.\r | |
327 | \r | |
328 | If StartBit is greater than 31, then ASSERT().\r | |
329 | If EndBit is greater than 31, then ASSERT().\r | |
330 | If EndBit is less than StartBit, then ASSERT().\r | |
331 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
332 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
333 | \r | |
334 | @param Index The 32-bit MSR index to write.\r | |
335 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
336 | Range 0..31.\r | |
337 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
338 | Range 0..31.\r | |
339 | @param AndData The value to AND with the read value from the MSR.\r | |
340 | @param OrData The value to OR with the result of the AND operation.\r | |
341 | \r | |
342 | @return The lower 32-bit of the value written to the MSR.\r | |
343 | \r | |
344 | **/\r | |
345 | UINT32\r | |
346 | EFIAPI\r | |
347 | AsmMsrBitFieldAndThenOr32 (\r | |
348 | IN UINT32 Index,\r | |
349 | IN UINTN StartBit,\r | |
350 | IN UINTN EndBit,\r | |
351 | IN UINT32 AndData,\r | |
352 | IN UINT32 OrData\r | |
353 | )\r | |
354 | {\r | |
355 | ASSERT (EndBit < sizeof (AndData) * 8);\r | |
356 | ASSERT (StartBit <= EndBit);\r | |
357 | return (UINT32)AsmMsrBitFieldAndThenOr64 (\r | |
358 | Index,\r | |
359 | StartBit,\r | |
360 | EndBit,\r | |
361 | AndData,\r | |
362 | OrData\r | |
363 | );\r | |
364 | }\r | |
365 | \r | |
366 | /**\r | |
367 | Reads a 64-bit MSR, performs a bitwise OR, and writes the result\r | |
368 | back to the 64-bit MSR.\r | |
369 | \r | |
370 | Reads the 64-bit MSR specified by Index, performs a bitwise OR\r | |
371 | between the read result and the value specified by OrData, and writes the\r | |
372 | result to the 64-bit MSR specified by Index. The value written to the MSR is\r | |
373 | returned. No parameter checking is performed on Index or OrData, and some of\r | |
374 | these may cause CPU exceptions. The caller must either guarantee that Index\r | |
375 | and OrData are valid, or the caller must establish proper exception handlers.\r | |
376 | This function is only available on IA-32 and x64.\r | |
377 | \r | |
378 | @param Index The 32-bit MSR index to write.\r | |
379 | @param OrData The value to OR with the read value from the MSR.\r | |
380 | \r | |
381 | @return The value written back to the MSR.\r | |
382 | \r | |
383 | **/\r | |
384 | UINT64\r | |
385 | EFIAPI\r | |
386 | AsmMsrOr64 (\r | |
387 | IN UINT32 Index,\r | |
388 | IN UINT64 OrData\r | |
389 | )\r | |
390 | {\r | |
391 | return AsmWriteMsr64 (Index, AsmReadMsr64 (Index) | OrData);\r | |
392 | }\r | |
393 | \r | |
394 | /**\r | |
395 | Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the\r | |
396 | 64-bit MSR.\r | |
397 | \r | |
398 | Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r | |
399 | read result and the value specified by OrData, and writes the result to the\r | |
400 | 64-bit MSR specified by Index. The value written to the MSR is returned. No\r | |
401 | parameter checking is performed on Index or OrData, and some of these may\r | |
402 | cause CPU exceptions. The caller must either guarantee that Index and OrData\r | |
403 | are valid, or the caller must establish proper exception handlers. This\r | |
404 | function is only available on IA-32 and x64.\r | |
405 | \r | |
406 | @param Index The 32-bit MSR index to write.\r | |
407 | @param AndData The value to AND with the read value from the MSR.\r | |
408 | \r | |
409 | @return The value written back to the MSR.\r | |
410 | \r | |
411 | **/\r | |
412 | UINT64\r | |
413 | EFIAPI\r | |
414 | AsmMsrAnd64 (\r | |
415 | IN UINT32 Index,\r | |
416 | IN UINT64 AndData\r | |
417 | )\r | |
418 | {\r | |
419 | return AsmWriteMsr64 (Index, AsmReadMsr64 (Index) & AndData);\r | |
420 | }\r | |
421 | \r | |
422 | /**\r | |
423 | Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise\r | |
424 | OR, and writes the result back to the 64-bit MSR.\r | |
425 | \r | |
426 | Reads the 64-bit MSR specified by Index, performs a bitwise AND between read\r | |
427 | result and the value specified by AndData, performs a bitwise OR\r | |
428 | between the result of the AND operation and the value specified by OrData,\r | |
429 | and writes the result to the 64-bit MSR specified by Index. The value written\r | |
430 | to the MSR is returned. No parameter checking is performed on Index, AndData,\r | |
431 | or OrData, and some of these may cause CPU exceptions. The caller must either\r | |
432 | guarantee that Index, AndData, and OrData are valid, or the caller must\r | |
433 | establish proper exception handlers. This function is only available on IA-32\r | |
434 | and x64.\r | |
435 | \r | |
436 | @param Index The 32-bit MSR index to write.\r | |
437 | @param AndData The value to AND with the read value from the MSR.\r | |
438 | @param OrData The value to OR with the result of the AND operation.\r | |
439 | \r | |
440 | @return The value written back to the MSR.\r | |
441 | \r | |
442 | **/\r | |
443 | UINT64\r | |
444 | EFIAPI\r | |
445 | AsmMsrAndThenOr64 (\r | |
446 | IN UINT32 Index,\r | |
447 | IN UINT64 AndData,\r | |
448 | IN UINT64 OrData\r | |
449 | )\r | |
450 | {\r | |
451 | return AsmWriteMsr64 (Index, (AsmReadMsr64 (Index) & AndData) | OrData);\r | |
452 | }\r | |
453 | \r | |
454 | /**\r | |
455 | Reads a bit field of an MSR.\r | |
456 | \r | |
457 | Reads the bit field in the 64-bit MSR. The bit field is specified by the\r | |
458 | StartBit and the EndBit. The value of the bit field is returned. The caller\r | |
459 | must either guarantee that Index is valid, or the caller must set up\r | |
460 | exception handlers to catch the exceptions. This function is only available\r | |
461 | on IA-32 and x64.\r | |
462 | \r | |
463 | If StartBit is greater than 63, then ASSERT().\r | |
464 | If EndBit is greater than 63, then ASSERT().\r | |
465 | If EndBit is less than StartBit, then ASSERT().\r | |
466 | \r | |
467 | @param Index The 32-bit MSR index to read.\r | |
468 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
469 | Range 0..63.\r | |
470 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
471 | Range 0..63.\r | |
472 | \r | |
473 | @return The value read from the MSR.\r | |
474 | \r | |
475 | **/\r | |
476 | UINT64\r | |
477 | EFIAPI\r | |
478 | AsmMsrBitFieldRead64 (\r | |
479 | IN UINT32 Index,\r | |
480 | IN UINTN StartBit,\r | |
481 | IN UINTN EndBit\r | |
482 | )\r | |
483 | {\r | |
484 | return BitFieldRead64 (AsmReadMsr64 (Index), StartBit, EndBit);\r | |
485 | }\r | |
486 | \r | |
487 | /**\r | |
488 | Writes a bit field to an MSR.\r | |
489 | \r | |
490 | Writes Value to a bit field in a 64-bit MSR. The bit field is specified by\r | |
491 | the StartBit and the EndBit. All other bits in the destination MSR are\r | |
492 | preserved. The MSR written is returned. The caller must either guarantee\r | |
493 | that Index and the data written is valid, or the caller must set up exception\r | |
494 | handlers to catch the exceptions. This function is only available on IA-32 and x64.\r | |
495 | \r | |
496 | If StartBit is greater than 63, then ASSERT().\r | |
497 | If EndBit is greater than 63, then ASSERT().\r | |
498 | If EndBit is less than StartBit, then ASSERT().\r | |
499 | If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
500 | \r | |
501 | @param Index The 32-bit MSR index to write.\r | |
502 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
503 | Range 0..63.\r | |
504 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
505 | Range 0..63.\r | |
506 | @param Value The new value of the bit field.\r | |
507 | \r | |
508 | @return The value written back to the MSR.\r | |
509 | \r | |
510 | **/\r | |
511 | UINT64\r | |
512 | EFIAPI\r | |
513 | AsmMsrBitFieldWrite64 (\r | |
514 | IN UINT32 Index,\r | |
515 | IN UINTN StartBit,\r | |
516 | IN UINTN EndBit,\r | |
517 | IN UINT64 Value\r | |
518 | )\r | |
519 | {\r | |
520 | return AsmWriteMsr64 (\r | |
521 | Index,\r | |
522 | BitFieldWrite64 (AsmReadMsr64 (Index), StartBit, EndBit, Value)\r | |
523 | );\r | |
524 | }\r | |
525 | \r | |
526 | /**\r | |
527 | Reads a bit field in a 64-bit MSR, performs a bitwise OR, and\r | |
528 | writes the result back to the bit field in the 64-bit MSR.\r | |
529 | \r | |
530 | Reads the 64-bit MSR specified by Index, performs a bitwise OR\r | |
531 | between the read result and the value specified by OrData, and writes the\r | |
532 | result to the 64-bit MSR specified by Index. The value written to the MSR is\r | |
533 | returned. Extra left bits in OrData are stripped. The caller must either\r | |
534 | guarantee that Index and the data written is valid, or the caller must set up\r | |
535 | exception handlers to catch the exceptions. This function is only available\r | |
536 | on IA-32 and x64.\r | |
537 | \r | |
538 | If StartBit is greater than 63, then ASSERT().\r | |
539 | If EndBit is greater than 63, then ASSERT().\r | |
540 | If EndBit is less than StartBit, then ASSERT().\r | |
541 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
542 | \r | |
543 | @param Index The 32-bit MSR index to write.\r | |
544 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
545 | Range 0..63.\r | |
546 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
547 | Range 0..63.\r | |
548 | @param OrData The value to OR with the read value from the bit field.\r | |
549 | \r | |
550 | @return The value written back to the MSR.\r | |
551 | \r | |
552 | **/\r | |
553 | UINT64\r | |
554 | EFIAPI\r | |
555 | AsmMsrBitFieldOr64 (\r | |
556 | IN UINT32 Index,\r | |
557 | IN UINTN StartBit,\r | |
558 | IN UINTN EndBit,\r | |
559 | IN UINT64 OrData\r | |
560 | )\r | |
561 | {\r | |
562 | return AsmWriteMsr64 (\r | |
563 | Index,\r | |
564 | BitFieldOr64 (AsmReadMsr64 (Index), StartBit, EndBit, OrData)\r | |
565 | );\r | |
566 | }\r | |
567 | \r | |
568 | /**\r | |
569 | Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the\r | |
570 | result back to the bit field in the 64-bit MSR.\r | |
571 | \r | |
572 | Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r | |
573 | read result and the value specified by AndData, and writes the result to the\r | |
574 | 64-bit MSR specified by Index. The value written to the MSR is returned.\r | |
575 | Extra left bits in AndData are stripped. The caller must either guarantee\r | |
576 | that Index and the data written is valid, or the caller must set up exception\r | |
577 | handlers to catch the exceptions. This function is only available on IA-32\r | |
578 | and x64.\r | |
579 | \r | |
580 | If StartBit is greater than 63, then ASSERT().\r | |
581 | If EndBit is greater than 63, then ASSERT().\r | |
582 | If EndBit is less than StartBit, then ASSERT().\r | |
583 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
584 | \r | |
585 | @param Index The 32-bit MSR index to write.\r | |
586 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
587 | Range 0..63.\r | |
588 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
589 | Range 0..63.\r | |
590 | @param AndData The value to AND with the read value from the bit field.\r | |
591 | \r | |
592 | @return The value written back to the MSR.\r | |
593 | \r | |
594 | **/\r | |
595 | UINT64\r | |
596 | EFIAPI\r | |
597 | AsmMsrBitFieldAnd64 (\r | |
598 | IN UINT32 Index,\r | |
599 | IN UINTN StartBit,\r | |
600 | IN UINTN EndBit,\r | |
601 | IN UINT64 AndData\r | |
602 | )\r | |
603 | {\r | |
604 | return AsmWriteMsr64 (\r | |
605 | Index,\r | |
606 | BitFieldAnd64 (AsmReadMsr64 (Index), StartBit, EndBit, AndData)\r | |
607 | );\r | |
608 | }\r | |
609 | \r | |
610 | /**\r | |
611 | Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a\r | |
612 | bitwise OR, and writes the result back to the bit field in the\r | |
613 | 64-bit MSR.\r | |
614 | \r | |
615 | Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by\r | |
616 | a bitwise OR between the read result and the value specified by\r | |
617 | AndData, and writes the result to the 64-bit MSR specified by Index. The\r | |
618 | value written to the MSR is returned. Extra left bits in both AndData and\r | |
619 | OrData are stripped. The caller must either guarantee that Index and the data\r | |
620 | written is valid, or the caller must set up exception handlers to catch the\r | |
621 | exceptions. This function is only available on IA-32 and x64.\r | |
622 | \r | |
623 | If StartBit is greater than 63, then ASSERT().\r | |
624 | If EndBit is greater than 63, then ASSERT().\r | |
625 | If EndBit is less than StartBit, then ASSERT().\r | |
626 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
627 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
628 | \r | |
629 | @param Index The 32-bit MSR index to write.\r | |
630 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
631 | Range 0..63.\r | |
632 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
633 | Range 0..63.\r | |
634 | @param AndData The value to AND with the read value from the bit field.\r | |
635 | @param OrData The value to OR with the result of the AND operation.\r | |
636 | \r | |
637 | @return The value written back to the MSR.\r | |
638 | \r | |
639 | **/\r | |
640 | UINT64\r | |
641 | EFIAPI\r | |
642 | AsmMsrBitFieldAndThenOr64 (\r | |
643 | IN UINT32 Index,\r | |
644 | IN UINTN StartBit,\r | |
645 | IN UINTN EndBit,\r | |
646 | IN UINT64 AndData,\r | |
647 | IN UINT64 OrData\r | |
648 | )\r | |
649 | {\r | |
650 | return AsmWriteMsr64 (\r | |
651 | Index,\r | |
652 | BitFieldAndThenOr64 (\r | |
653 | AsmReadMsr64 (Index),\r | |
654 | StartBit,\r | |
655 | EndBit,\r | |
656 | AndData,\r | |
657 | OrData\r | |
658 | )\r | |
659 | );\r | |
660 | }\r |