TianoCore EDK2 master
Loading...
Searching...
No Matches
IoLib.c
Go to the documentation of this file.
1
10#include "IoLibTdx.h"
11
27UINT64
28EFIAPI
30 IN UINTN Port
31 )
32{
33 ASSERT (FALSE);
34 return 0;
35}
36
53UINT64
54EFIAPI
56 IN UINTN Port,
57 IN UINT64 Value
58 )
59{
60 ASSERT (FALSE);
61 return 0;
62}
63
80UINT8
81EFIAPI
83 IN UINTN Address
84 )
85{
86 UINT8 Value;
87 BOOLEAN Flag;
88
89 Flag = FilterBeforeMmIoRead (FilterWidth8, Address, &Value);
90 if (Flag) {
91 MemoryFence ();
92
93 if (IsTdxGuest ()) {
94 Value = TdMmioRead8 (Address);
95 } else {
96 Value = *(volatile UINT8 *)Address;
97 }
98
99 MemoryFence ();
100 }
101
102 FilterAfterMmIoRead (FilterWidth8, Address, &Value);
103
104 return Value;
105}
106
124UINT8
125EFIAPI
127 IN UINTN Address,
128 IN UINT8 Value
129 )
130{
131 BOOLEAN Flag;
132
133 Flag = FilterBeforeMmIoWrite (FilterWidth8, Address, &Value);
134 if (Flag) {
135 MemoryFence ();
136
137 if (IsTdxGuest ()) {
138 TdMmioWrite8 (Address, Value);
139 } else {
140 *(volatile UINT8 *)Address = Value;
141 }
142
143 MemoryFence ();
144 }
145
146 FilterAfterMmIoWrite (FilterWidth8, Address, &Value);
147
148 return Value;
149}
150
168UINT16
169EFIAPI
171 IN UINTN Address
172 )
173{
174 UINT16 Value;
175 BOOLEAN Flag;
176
177 ASSERT ((Address & 1) == 0);
178 Flag = FilterBeforeMmIoRead (FilterWidth16, Address, &Value);
179 if (Flag) {
180 MemoryFence ();
181
182 if (IsTdxGuest ()) {
183 Value = TdMmioRead16 (Address);
184 } else {
185 Value = *(volatile UINT16 *)Address;
186 }
187
188 MemoryFence ();
189 }
190
191 FilterAfterMmIoRead (FilterWidth16, Address, &Value);
192
193 return Value;
194}
195
214UINT16
215EFIAPI
217 IN UINTN Address,
218 IN UINT16 Value
219 )
220{
221 BOOLEAN Flag;
222
223 ASSERT ((Address & 1) == 0);
224
225 Flag = FilterBeforeMmIoWrite (FilterWidth16, Address, &Value);
226 if (Flag) {
227 MemoryFence ();
228
229 if (IsTdxGuest ()) {
230 TdMmioWrite16 (Address, Value);
231 } else {
232 *(volatile UINT16 *)Address = Value;
233 }
234
235 MemoryFence ();
236 }
237
238 FilterAfterMmIoWrite (FilterWidth16, Address, &Value);
239
240 return Value;
241}
242
260UINT32
261EFIAPI
263 IN UINTN Address
264 )
265{
266 UINT32 Value;
267 BOOLEAN Flag;
268
269 ASSERT ((Address & 3) == 0);
270
271 Flag = FilterBeforeMmIoRead (FilterWidth32, Address, &Value);
272 if (Flag) {
273 MemoryFence ();
274
275 if (IsTdxGuest ()) {
276 Value = TdMmioRead32 (Address);
277 } else {
278 Value = *(volatile UINT32 *)Address;
279 }
280
281 MemoryFence ();
282 }
283
284 FilterAfterMmIoRead (FilterWidth32, Address, &Value);
285
286 return Value;
287}
288
307UINT32
308EFIAPI
310 IN UINTN Address,
311 IN UINT32 Value
312 )
313{
314 BOOLEAN Flag;
315
316 ASSERT ((Address & 3) == 0);
317
318 Flag = FilterBeforeMmIoWrite (FilterWidth32, Address, &Value);
319 if (Flag) {
320 MemoryFence ();
321
322 if (IsTdxGuest ()) {
323 TdMmioWrite32 (Address, Value);
324 } else {
325 *(volatile UINT32 *)Address = Value;
326 }
327
328 MemoryFence ();
329 }
330
331 FilterAfterMmIoWrite (FilterWidth32, Address, &Value);
332
333 return Value;
334}
335
353UINT64
354EFIAPI
356 IN UINTN Address
357 )
358{
359 UINT64 Value;
360 BOOLEAN Flag;
361
362 ASSERT ((Address & 7) == 0);
363
364 Flag = FilterBeforeMmIoRead (FilterWidth64, Address, &Value);
365 if (Flag) {
366 MemoryFence ();
367
368 if (IsTdxGuest ()) {
369 Value = TdMmioRead64 (Address);
370 } else {
371 Value = *(volatile UINT64 *)Address;
372 }
373
374 MemoryFence ();
375 }
376
377 FilterAfterMmIoRead (FilterWidth64, Address, &Value);
378
379 return Value;
380}
381
398UINT64
399EFIAPI
401 IN UINTN Address,
402 IN UINT64 Value
403 )
404{
405 BOOLEAN Flag;
406
407 ASSERT ((Address & 7) == 0);
408
409 Flag = FilterBeforeMmIoWrite (FilterWidth64, Address, &Value);
410 if (Flag) {
411 MemoryFence ();
412
413 if (IsTdxGuest ()) {
414 TdMmioWrite64 (Address, Value);
415 } else {
416 *(volatile UINT64 *)Address = Value;
417 }
418
419 MemoryFence ();
420 }
421
422 FilterAfterMmIoWrite (FilterWidth64, Address, &Value);
423
424 return Value;
425}
UINT64 UINTN
UINT64 EFIAPI MmioWrite64(IN UINTN Address, IN UINT64 Value)
Definition: IoLib.c:400
UINT64 EFIAPI IoRead64(IN UINTN Port)
Definition: IoLib.c:29
UINT64 EFIAPI IoWrite64(IN UINTN Port, IN UINT64 Value)
Definition: IoLib.c:55
UINT64 EFIAPI MmioRead64(IN UINTN Address)
Definition: IoLib.c:355
UINT16 EFIAPI MmioRead16(IN UINTN Address)
Definition: IoLib.c:170
UINT8 EFIAPI MmioRead8(IN UINTN Address)
Definition: IoLib.c:82
UINT8 EFIAPI MmioWrite8(IN UINTN Address, IN UINT8 Value)
Definition: IoLib.c:126
UINT32 EFIAPI MmioRead32(IN UINTN Address)
Definition: IoLib.c:262
UINT16 EFIAPI MmioWrite16(IN UINTN Address, IN UINT16 Value)
Definition: IoLib.c:216
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
Definition: IoLib.c:309
VOID EFIAPI MemoryFence(VOID)
Definition: CpuBreakpoint.c:42
UINT32 EFIAPI TdMmioRead32(IN UINTN Address)
UINT64 EFIAPI TdMmioRead64(IN UINTN Address)
UINT8 EFIAPI TdMmioRead8(IN UINTN Address)
UINT16 EFIAPI TdMmioRead16(IN UINTN Address)
UINT8 EFIAPI TdMmioWrite8(IN UINTN Address, IN UINT8 Value)
UINT64 EFIAPI TdMmioWrite64(IN UINTN Address, IN UINT64 Value)
UINT32 EFIAPI TdMmioWrite32(IN UINTN Address, IN UINT32 Value)
UINT16 EFIAPI TdMmioWrite16(IN UINTN Address, IN UINT16 Value)
BOOLEAN EFIAPI IsTdxGuest(VOID)
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
VOID EFIAPI FilterAfterMmIoWrite(IN FILTER_IO_WIDTH Width, IN UINTN Address, IN VOID *Buffer)
BOOLEAN EFIAPI FilterBeforeMmIoWrite(IN FILTER_IO_WIDTH Width, IN UINTN Address, IN VOID *Buffer)
BOOLEAN EFIAPI FilterBeforeMmIoRead(IN FILTER_IO_WIDTH Width, IN UINTN Address, IN OUT VOID *Buffer)
VOID EFIAPI FilterAfterMmIoRead(IN FILTER_IO_WIDTH Width, IN UINTN Address, IN VOID *Buffer)