TianoCore EDK2 master
Loading...
Searching...
No Matches
IoLibMsc.c
Go to the documentation of this file.
1
17#include "IoLibTdx.h"
18
19//
20// Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.
21//
22
23int
24_inp (
25 unsigned short port
26 );
27
28unsigned short
29_inpw (
30 unsigned short port
31 );
32
33unsigned long
34_inpd (
35 unsigned short port
36 );
37
38int
39_outp (
40 unsigned short port,
41 int databyte
42 );
43
44unsigned short
45_outpw (
46 unsigned short port,
47 unsigned short dataword
48 );
49
50unsigned long
51_outpd (
52 unsigned short port,
53 unsigned long dataword
54 );
55
56void
57_ReadWriteBarrier (
58 void
59 );
60
61#pragma intrinsic(_inp)
62#pragma intrinsic(_inpw)
63#pragma intrinsic(_inpd)
64#pragma intrinsic(_outp)
65#pragma intrinsic(_outpw)
66#pragma intrinsic(_outpd)
67#pragma intrinsic(_ReadWriteBarrier)
68
69//
70// _ReadWriteBarrier() forces memory reads and writes to complete at the point
71// in the call. This is only a hint to the compiler and does emit code.
72// In past versions of the compiler, _ReadWriteBarrier was enforced only
73// locally and did not affect functions up the call tree. In Visual C++
74// 2005, _ReadWriteBarrier is enforced all the way up the call tree.
75//
76
93UINT8
94EFIAPI
96 IN UINTN Port
97 )
98{
99 UINT8 Value;
100 BOOLEAN Flag;
101
102 Flag = FilterBeforeIoRead (FilterWidth8, Port, &Value);
103 if (Flag) {
104 if (IsTdxGuest ()) {
105 Value = TdIoRead8 (Port);
106 } else {
107 _ReadWriteBarrier ();
108 Value = (UINT8)_inp ((UINT16)Port);
109 _ReadWriteBarrier ();
110 }
111 }
112
113 FilterAfterIoRead (FilterWidth8, Port, &Value);
114
115 return Value;
116}
117
135UINT8
136EFIAPI
138 IN UINTN Port,
139 IN UINT8 Value
140 )
141{
142 BOOLEAN Flag;
143
144 Flag = FilterBeforeIoWrite (FilterWidth8, Port, &Value);
145 if (Flag) {
146 if (IsTdxGuest ()) {
147 TdIoWrite8 (Port, Value);
148 } else {
149 _ReadWriteBarrier ();
150 (UINT8)_outp ((UINT16)Port, Value);
151 _ReadWriteBarrier ();
152 }
153 }
154
155 FilterAfterIoWrite (FilterWidth8, Port, &Value);
156
157 return Value;
158}
159
177UINT16
178EFIAPI
180 IN UINTN Port
181 )
182{
183 UINT16 Value;
184 BOOLEAN Flag;
185
186 ASSERT ((Port & 1) == 0);
187
188 Flag = FilterBeforeIoRead (FilterWidth16, Port, &Value);
189 if (Flag) {
190 if (IsTdxGuest ()) {
191 Value = TdIoRead16 (Port);
192 } else {
193 _ReadWriteBarrier ();
194 Value = _inpw ((UINT16)Port);
195 _ReadWriteBarrier ();
196 }
197 }
198
199 FilterBeforeIoRead (FilterWidth16, Port, &Value);
200
201 return Value;
202}
203
222UINT16
223EFIAPI
225 IN UINTN Port,
226 IN UINT16 Value
227 )
228{
229 BOOLEAN Flag;
230
231 ASSERT ((Port & 1) == 0);
232
233 Flag = FilterBeforeIoWrite (FilterWidth16, Port, &Value);
234 if (Flag) {
235 if (IsTdxGuest ()) {
236 TdIoWrite16 (Port, Value);
237 } else {
238 _ReadWriteBarrier ();
239 _outpw ((UINT16)Port, Value);
240 _ReadWriteBarrier ();
241 }
242 }
243
244 FilterAfterIoWrite (FilterWidth16, Port, &Value);
245
246 return Value;
247}
248
266UINT32
267EFIAPI
269 IN UINTN Port
270 )
271{
272 UINT32 Value;
273 BOOLEAN Flag;
274
275 ASSERT ((Port & 3) == 0);
276
277 Flag = FilterBeforeIoRead (FilterWidth32, Port, &Value);
278 if (Flag) {
279 if (IsTdxGuest ()) {
280 Value = TdIoRead32 (Port);
281 } else {
282 _ReadWriteBarrier ();
283 Value = _inpd ((UINT16)Port);
284 _ReadWriteBarrier ();
285 }
286 }
287
288 FilterAfterIoRead (FilterWidth32, Port, &Value);
289
290 return Value;
291}
292
311UINT32
312EFIAPI
314 IN UINTN Port,
315 IN UINT32 Value
316 )
317{
318 BOOLEAN Flag;
319
320 ASSERT ((Port & 3) == 0);
321
322 Flag = FilterBeforeIoWrite (FilterWidth32, Port, &Value);
323 if (Flag) {
324 if (IsTdxGuest ()) {
325 TdIoWrite32 (Port, Value);
326 } else {
327 _ReadWriteBarrier ();
328 _outpd ((UINT16)Port, Value);
329 _ReadWriteBarrier ();
330 }
331 }
332
333 FilterAfterIoWrite (FilterWidth32, Port, &Value);
334
335 return Value;
336}
UINT64 UINTN
UINT16 EFIAPI TdIoRead16(IN UINTN Port)
UINT32 EFIAPI TdIoWrite32(IN UINTN Port, IN UINT32 Value)
UINT16 EFIAPI TdIoWrite16(IN UINTN Port, IN UINT16 Value)
UINT32 EFIAPI TdIoRead32(IN UINTN Port)
BOOLEAN EFIAPI IsTdxGuest(VOID)
UINT8 EFIAPI TdIoWrite8(IN UINTN Port, IN UINT8 Value)
UINT8 EFIAPI TdIoRead8(IN UINTN Port)
UINT8 EFIAPI IoWrite8(IN UINTN Port, IN UINT8 Value)
Definition: IoLibMsc.c:137
UINT8 EFIAPI IoRead8(IN UINTN Port)
Definition: IoLibMsc.c:95
UINT16 EFIAPI IoRead16(IN UINTN Port)
Definition: IoLibMsc.c:179
UINT32 EFIAPI IoRead32(IN UINTN Port)
Definition: IoLibMsc.c:268
UINT32 EFIAPI IoWrite32(IN UINTN Port, IN UINT32 Value)
Definition: IoLibMsc.c:313
UINT16 EFIAPI IoWrite16(IN UINTN Port, IN UINT16 Value)
Definition: IoLibMsc.c:224
#define IN
Definition: Base.h:279
VOID EFIAPI FilterAfterIoRead(IN FILTER_IO_WIDTH Width, IN UINTN Address, IN VOID *Buffer)
BOOLEAN EFIAPI FilterBeforeIoWrite(IN FILTER_IO_WIDTH Width, IN UINTN Address, IN VOID *Buffer)
VOID EFIAPI FilterAfterIoWrite(IN FILTER_IO_WIDTH Width, IN UINTN Address, IN VOID *Buffer)
BOOLEAN EFIAPI FilterBeforeIoRead(IN FILTER_IO_WIDTH Width, IN UINTN Address, IN OUT VOID *Buffer)