]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibMsc.c
2 I/O Library. This file has compiler specifics for Microsft C as there is no
3 ANSI C standard for doing IO.
5 MSC - uses intrinsic functions and the optimize will remove the function call
8 We don't advocate putting compiler specifics in libraries or drivers but there
9 is no other way to make this work.
11 Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
12 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include "BaseIoLibIntrinsicInternal.h"
20 // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.
47 unsigned short dataword
53 unsigned long dataword
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)
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.
78 Reads an 8-bit I/O port.
80 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
81 This function must guarantee that all I/O read and write operations are
84 If 8-bit I/O port operations are not supported, then ASSERT().
86 For Td guest TDVMCALL_IO is invoked to read I/O port.
88 @param Port The I/O port to read.
90 @return The value read.
102 Flag
= FilterBeforeIoRead (FilterWidth8
, Port
, &Value
);
105 Value
= TdIoRead8 (Port
);
107 _ReadWriteBarrier ();
108 Value
= (UINT8
)_inp ((UINT16
)Port
);
109 _ReadWriteBarrier ();
113 FilterAfterIoRead (FilterWidth8
, Port
, &Value
);
119 Writes an 8-bit I/O port.
121 Writes the 8-bit I/O port specified by Port with the value specified by Value
122 and returns Value. This function must guarantee that all I/O read and write
123 operations are serialized.
125 If 8-bit I/O port operations are not supported, then ASSERT().
127 For Td guest TDVMCALL_IO is invoked to write I/O port.
129 @param Port The I/O port to write.
130 @param Value The value to write to the I/O port.
132 @return The value written to the I/O port.
144 Flag
= FilterBeforeIoWrite (FilterWidth8
, Port
, &Value
);
147 TdIoWrite8 (Port
, Value
);
149 _ReadWriteBarrier ();
150 (UINT8
)_outp ((UINT16
)Port
, Value
);
151 _ReadWriteBarrier ();
155 FilterAfterIoWrite (FilterWidth8
, Port
, &Value
);
161 Reads a 16-bit I/O port.
163 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
164 This function must guarantee that all I/O read and write operations are
167 If 16-bit I/O port operations are not supported, then ASSERT().
168 If Port is not aligned on a 16-bit boundary, then ASSERT().
170 For Td guest TDVMCALL_IO is invoked to read I/O port.
172 @param Port The I/O port to read.
174 @return The value read.
186 ASSERT ((Port
& 1) == 0);
188 Flag
= FilterBeforeIoRead (FilterWidth16
, Port
, &Value
);
191 Value
= TdIoRead16 (Port
);
193 _ReadWriteBarrier ();
194 Value
= _inpw ((UINT16
)Port
);
195 _ReadWriteBarrier ();
199 FilterBeforeIoRead (FilterWidth16
, Port
, &Value
);
205 Writes a 16-bit I/O port.
207 Writes the 16-bit I/O port specified by Port with the value specified by Value
208 and returns Value. This function must guarantee that all I/O read and write
209 operations are serialized.
211 If 16-bit I/O port operations are not supported, then ASSERT().
212 If Port is not aligned on a 16-bit boundary, then ASSERT().
214 For Td guest TDVMCALL_IO is invoked to write I/O port.
216 @param Port The I/O port to write.
217 @param Value The value to write to the I/O port.
219 @return The value written to the I/O port.
231 ASSERT ((Port
& 1) == 0);
233 Flag
= FilterBeforeIoWrite (FilterWidth16
, Port
, &Value
);
236 TdIoWrite16 (Port
, Value
);
238 _ReadWriteBarrier ();
239 _outpw ((UINT16
)Port
, Value
);
240 _ReadWriteBarrier ();
244 FilterAfterIoWrite (FilterWidth16
, Port
, &Value
);
250 Reads a 32-bit I/O port.
252 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
253 This function must guarantee that all I/O read and write operations are
256 If 32-bit I/O port operations are not supported, then ASSERT().
257 If Port is not aligned on a 32-bit boundary, then ASSERT().
259 For Td guest TDVMCALL_IO is invoked to read I/O port.
261 @param Port The I/O port to read.
263 @return The value read.
275 ASSERT ((Port
& 3) == 0);
277 Flag
= FilterBeforeIoRead (FilterWidth32
, Port
, &Value
);
280 Value
= TdIoRead32 (Port
);
282 _ReadWriteBarrier ();
283 Value
= _inpd ((UINT16
)Port
);
284 _ReadWriteBarrier ();
288 FilterAfterIoRead (FilterWidth32
, Port
, &Value
);
294 Writes a 32-bit I/O port.
296 Writes the 32-bit I/O port specified by Port with the value specified by Value
297 and returns Value. This function must guarantee that all I/O read and write
298 operations are serialized.
300 If 32-bit I/O port operations are not supported, then ASSERT().
301 If Port is not aligned on a 32-bit boundary, then ASSERT().
303 For Td guest TDVMCALL_IO is invoked to write I/O port.
305 @param Port The I/O port to write.
306 @param Value The value to write to the I/O port.
308 @return The value written to the I/O port.
320 ASSERT ((Port
& 3) == 0);
322 Flag
= FilterBeforeIoWrite (FilterWidth32
, Port
, &Value
);
325 TdIoWrite32 (Port
, Value
);
327 _ReadWriteBarrier ();
328 _outpd ((UINT16
)Port
, Value
);
329 _ReadWriteBarrier ();
333 FilterAfterIoWrite (FilterWidth32
, Port
, &Value
);