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 - 2007, Intel Corporation<BR>
12 All rights reserved. This program and the accompanying materials
13 are licensed and made available under the terms and conditions of the BSD License
14 which accompanies this distribution. The full text of the license may be found at
15 http://opensource.org/licenses/bsd-license.php
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 // Include common header file for this module.
26 #include "BaseIoLibIntrinsicInternal.h"
29 // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics
31 int _inp (unsigned short port
);
32 unsigned short _inpw (unsigned short port
);
33 unsigned long _inpd (unsigned short port
);
34 int _outp (unsigned short port
, int databyte
);
35 unsigned short _outpw (unsigned short port
, unsigned short dataword
);
36 unsigned long _outpd (unsigned short port
, unsigned long dataword
);
37 void _ReadWriteBarrier (void);
39 #pragma intrinsic(_inp)
40 #pragma intrinsic(_inpw)
41 #pragma intrinsic(_inpd)
42 #pragma intrinsic(_outp)
43 #pragma intrinsic(_outpw)
44 #pragma intrinsic(_outpd)
45 #pragma intrinsic(_ReadWriteBarrier)
48 // _ReadWriteBarrier() forces memory reads and writes to complete at the point
49 // in the call. This is only a hint to the compiler and does emit code.
50 // In past versions of the compiler, _ReadWriteBarrier was enforced only
51 // locally and did not affect functions up the call tree. In Visual C++
52 // 2005, _ReadWriteBarrier is enforced all the way up the call tree.
56 Reads an 8-bit I/O port.
58 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
59 This function must guarantee that all I/O read and write operations are
62 If 8-bit I/O port operations are not supported, then ASSERT().
64 @param Port The I/O port to read.
66 @return The value read.
78 Value
= (UINT8
)_inp ((UINT16
)Port
);
84 Writes an 8-bit I/O port.
86 Writes the 8-bit I/O port specified by Port with the value specified by Value
87 and returns Value. This function must guarantee that all I/O read and write
88 operations are serialized.
90 If 8-bit I/O port operations are not supported, then ASSERT().
92 @param Port The I/O port to write.
93 @param Value The value to write to the I/O port.
95 @return The value written the I/O port.
105 _ReadWriteBarrier ();
106 (UINT8
)_outp ((UINT16
)Port
, Value
);
107 _ReadWriteBarrier ();
112 Reads a 16-bit I/O port.
114 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
115 This function must guarantee that all I/O read and write operations are
118 If 16-bit I/O port operations are not supported, then ASSERT().
120 @param Port The I/O port to read.
122 @return The value read.
133 ASSERT ((Port
& 1) == 0);
134 _ReadWriteBarrier ();
135 Value
= _inpw ((UINT16
)Port
);
136 _ReadWriteBarrier ();
141 Writes a 16-bit I/O port.
143 Writes the 16-bit I/O port specified by Port with the value specified by Value
144 and returns Value. This function must guarantee that all I/O read and write
145 operations are serialized.
147 If 16-bit I/O port operations are not supported, then ASSERT().
149 @param Port The I/O port to write.
150 @param Value The value to write to the I/O port.
152 @return The value written the I/O port.
162 ASSERT ((Port
& 1) == 0);
163 _ReadWriteBarrier ();
164 _outpw ((UINT16
)Port
, Value
);
165 _ReadWriteBarrier ();
170 Reads a 32-bit I/O port.
172 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
173 This function must guarantee that all I/O read and write operations are
176 If 32-bit I/O port operations are not supported, then ASSERT().
178 @param Port The I/O port to read.
180 @return The value read.
191 ASSERT ((Port
& 3) == 0);
192 _ReadWriteBarrier ();
193 Value
= _inpd ((UINT16
)Port
);
194 _ReadWriteBarrier ();
199 Writes a 32-bit I/O port.
201 Writes the 32-bit I/O port specified by Port with the value specified by Value
202 and returns Value. This function must guarantee that all I/O read and write
203 operations are serialized.
205 If 32-bit I/O port operations are not supported, then ASSERT().
207 @param Port The I/O port to write.
208 @param Value The value to write to the I/O port.
210 @return The value written the I/O port.
220 ASSERT ((Port
& 3) == 0);
221 _ReadWriteBarrier ();
222 _outpd ((UINT16
)Port
, Value
);
223 _ReadWriteBarrier ();
229 Reads an 8-bit MMIO register.
231 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
232 returned. This function must guarantee that all MMIO read and write
233 operations are serialized.
235 If 8-bit MMIO register operations are not supported, then ASSERT().
237 @param Address The MMIO register to read.
239 @return The value read.
250 Value
= *(volatile UINT8
*)Address
;
255 Writes an 8-bit MMIO register.
257 Writes the 8-bit MMIO register specified by Address with the value specified
258 by Value and returns Value. This function must guarantee that all MMIO read
259 and write operations are serialized.
261 If 8-bit MMIO register operations are not supported, then ASSERT().
263 @param Address The MMIO register to write.
264 @param Value The value to write to the MMIO register.
274 return *(volatile UINT8
*)Address
= Value
;
278 Reads a 16-bit MMIO register.
280 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
281 returned. This function must guarantee that all MMIO read and write
282 operations are serialized.
284 If 16-bit MMIO register operations are not supported, then ASSERT().
286 @param Address The MMIO register to read.
288 @return The value read.
299 ASSERT ((Address
& 1) == 0);
300 Value
= *(volatile UINT16
*)Address
;
305 Writes a 16-bit MMIO register.
307 Writes the 16-bit MMIO register specified by Address with the value specified
308 by Value and returns Value. This function must guarantee that all MMIO read
309 and write operations are serialized.
311 If 16-bit MMIO register operations are not supported, then ASSERT().
313 @param Address The MMIO register to write.
314 @param Value The value to write to the MMIO register.
324 ASSERT ((Address
& 1) == 0);
325 return *(volatile UINT16
*)Address
= Value
;
329 Reads a 32-bit MMIO register.
331 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
332 returned. This function must guarantee that all MMIO read and write
333 operations are serialized.
335 If 32-bit MMIO register operations are not supported, then ASSERT().
337 @param Address The MMIO register to read.
339 @return The value read.
350 ASSERT ((Address
& 3) == 0);
351 Value
= *(volatile UINT32
*)Address
;
356 Writes a 32-bit MMIO register.
358 Writes the 32-bit MMIO register specified by Address with the value specified
359 by Value and returns Value. This function must guarantee that all MMIO read
360 and write operations are serialized.
362 If 32-bit MMIO register operations are not supported, then ASSERT().
364 @param Address The MMIO register to write.
365 @param Value The value to write to the MMIO register.
375 ASSERT ((Address
& 3) == 0);
376 return *(volatile UINT32
*)Address
= Value
;
380 Reads a 64-bit MMIO register.
382 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
383 returned. This function must guarantee that all MMIO read and write
384 operations are serialized.
386 If 64-bit MMIO register operations are not supported, then ASSERT().
388 @param Address The MMIO register to read.
390 @return The value read.
401 ASSERT ((Address
& 7) == 0);
402 Value
= *(volatile UINT64
*)Address
;
407 Writes a 64-bit MMIO register.
409 Writes the 64-bit MMIO register specified by Address with the value specified
410 by Value and returns Value. This function must guarantee that all MMIO read
411 and write operations are serialized.
413 If 64-bit MMIO register operations are not supported, then ASSERT().
415 @param Address The MMIO register to write.
416 @param Value The value to write to the MMIO register.
426 ASSERT ((Address
& 7) == 0);
427 return *(volatile UINT64
*)Address
= Value
;