]>
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
18 #include "BaseIoLibIntrinsicInternal.h"
21 // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.
24 int _inp (unsigned short port
);
25 unsigned short _inpw (unsigned short port
);
26 unsigned long _inpd (unsigned short port
);
27 int _outp (unsigned short port
, int databyte
);
28 unsigned short _outpw (unsigned short port
, unsigned short dataword
);
29 unsigned long _outpd (unsigned short port
, unsigned long dataword
);
30 void _ReadWriteBarrier (void);
32 #pragma intrinsic(_inp)
33 #pragma intrinsic(_inpw)
34 #pragma intrinsic(_inpd)
35 #pragma intrinsic(_outp)
36 #pragma intrinsic(_outpw)
37 #pragma intrinsic(_outpd)
38 #pragma intrinsic(_ReadWriteBarrier)
41 // _ReadWriteBarrier() forces memory reads and writes to complete at the point
42 // in the call. This is only a hint to the compiler and does emit code.
43 // In past versions of the compiler, _ReadWriteBarrier was enforced only
44 // locally and did not affect functions up the call tree. In Visual C++
45 // 2005, _ReadWriteBarrier is enforced all the way up the call tree.
49 Reads an 8-bit I/O port.
51 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
52 This function must guarantee that all I/O read and write operations are
55 If 8-bit I/O port operations are not supported, then ASSERT().
57 @param Port The I/O port to read.
59 @return The value read.
71 Flag
= FilterBeforeIoRead (FilterWidth8
, Port
, &Value
);
74 Value
= (UINT8
)_inp ((UINT16
)Port
);
77 FilterAfterIoRead (FilterWidth8
, Port
, &Value
);
83 Writes an 8-bit I/O port.
85 Writes the 8-bit I/O port specified by Port with the value specified by Value
86 and returns Value. This function must guarantee that all I/O read and write
87 operations are serialized.
89 If 8-bit I/O port operations are not supported, then ASSERT().
91 @param Port The I/O port to write.
92 @param Value The value to write to the I/O port.
94 @return The value written to the I/O port.
106 Flag
= FilterBeforeIoWrite(FilterWidth8
, Port
, &Value
);
108 _ReadWriteBarrier ();
109 (UINT8
)_outp ((UINT16
)Port
, Value
);
110 _ReadWriteBarrier ();
112 FilterAfterIoWrite (FilterWidth8
, Port
, &Value
);
118 Reads a 16-bit I/O port.
120 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
121 This function must guarantee that all I/O read and write operations are
124 If 16-bit I/O port operations are not supported, then ASSERT().
125 If Port is not aligned on a 16-bit boundary, then ASSERT().
127 @param Port The I/O port to read.
129 @return The value read.
141 ASSERT ((Port
& 1) == 0);
143 Flag
= FilterBeforeIoRead (FilterWidth16
, Port
, &Value
);
145 _ReadWriteBarrier ();
146 Value
= _inpw ((UINT16
)Port
);
147 _ReadWriteBarrier ();
149 FilterBeforeIoRead (FilterWidth16
, Port
, &Value
);
155 Writes a 16-bit I/O port.
157 Writes the 16-bit I/O port specified by Port with the value specified by Value
158 and returns Value. This function must guarantee that all I/O read and write
159 operations are serialized.
161 If 16-bit I/O port operations are not supported, then ASSERT().
162 If Port is not aligned on a 16-bit boundary, then ASSERT().
164 @param Port The I/O port to write.
165 @param Value The value to write to the I/O port.
167 @return The value written to the I/O port.
179 ASSERT ((Port
& 1) == 0);
181 Flag
= FilterBeforeIoWrite(FilterWidth16
, Port
, &Value
);
183 _ReadWriteBarrier ();
184 _outpw ((UINT16
)Port
, Value
);
185 _ReadWriteBarrier ();
187 FilterAfterIoWrite (FilterWidth16
, Port
, &Value
);
193 Reads a 32-bit I/O port.
195 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
196 This function must guarantee that all I/O read and write operations are
199 If 32-bit I/O port operations are not supported, then ASSERT().
200 If Port is not aligned on a 32-bit boundary, then ASSERT().
202 @param Port The I/O port to read.
204 @return The value read.
216 ASSERT ((Port
& 3) == 0);
218 Flag
= FilterBeforeIoRead(FilterWidth32
, Port
, &Value
);
220 _ReadWriteBarrier ();
221 Value
= _inpd ((UINT16
)Port
);
222 _ReadWriteBarrier ();
224 FilterAfterIoRead (FilterWidth32
, Port
, &Value
);
230 Writes a 32-bit I/O port.
232 Writes the 32-bit I/O port specified by Port with the value specified by Value
233 and returns Value. This function must guarantee that all I/O read and write
234 operations are serialized.
236 If 32-bit I/O port operations are not supported, then ASSERT().
237 If Port is not aligned on a 32-bit boundary, then ASSERT().
239 @param Port The I/O port to write.
240 @param Value The value to write to the I/O port.
242 @return The value written to the I/O port.
254 ASSERT ((Port
& 3) == 0);
256 Flag
= FilterBeforeIoWrite(FilterWidth32
, Port
, &Value
);
258 _ReadWriteBarrier ();
259 _outpd ((UINT16
)Port
, Value
);
260 _ReadWriteBarrier ();
262 FilterAfterIoWrite (FilterWidth32
, Port
, &Value
);