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);
40 #pragma intrinsic(_inp)
41 #pragma intrinsic(_inpw)
42 #pragma intrinsic(_inpd)
43 #pragma intrinsic(_outp)
44 #pragma intrinsic(_outpw)
45 #pragma intrinsic(_outpd)
46 #pragma intrinsic(_ReadWriteBarrier)
49 // _ReadWriteBarrier() forces memory reads and writes to complete at the point
50 // in the call. This is only a hint to the compiler and does emit code.
51 // In past versions of the compiler, _ReadWriteBarrier was enforced only
52 // locally and did not affect functions up the call tree. In Visual C++
53 // 2005, _ReadWriteBarrier is enforced all the way up the call tree.
57 Reads an 8-bit I/O port.
59 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
60 This function must guarantee that all I/O read and write operations are
63 If 8-bit I/O port operations are not supported, then ASSERT().
65 @param Port The I/O port to read.
67 @return The value read.
79 Value
= (UINT8
)_inp ((UINT16
)Port
);
85 Writes an 8-bit I/O port.
87 Writes the 8-bit I/O port specified by Port with the value specified by Value
88 and returns Value. This function must guarantee that all I/O read and write
89 operations are serialized.
91 If 8-bit I/O port operations are not supported, then ASSERT().
93 @param Port The I/O port to write.
94 @param Value The value to write to the I/O port.
96 @return The value written the I/O port.
106 _ReadWriteBarrier ();
107 (UINT8
)_outp ((UINT16
)Port
, Value
);
108 _ReadWriteBarrier ();
113 Reads a 16-bit I/O port.
115 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
116 This function must guarantee that all I/O read and write operations are
119 If 16-bit I/O port operations are not supported, then ASSERT().
121 @param Port The I/O port to read.
123 @return The value read.
134 ASSERT ((Port
& 1) == 0);
135 _ReadWriteBarrier ();
136 Value
= _inpw ((UINT16
)Port
);
137 _ReadWriteBarrier ();
142 Writes a 16-bit I/O port.
144 Writes the 16-bit I/O port specified by Port with the value specified by Value
145 and returns Value. This function must guarantee that all I/O read and write
146 operations are serialized.
148 If 16-bit I/O port operations are not supported, then ASSERT().
150 @param Port The I/O port to write.
151 @param Value The value to write to the I/O port.
153 @return The value written the I/O port.
163 ASSERT ((Port
& 1) == 0);
164 _ReadWriteBarrier ();
165 _outpw ((UINT16
)Port
, Value
);
166 _ReadWriteBarrier ();
171 Reads a 32-bit I/O port.
173 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
174 This function must guarantee that all I/O read and write operations are
177 If 32-bit I/O port operations are not supported, then ASSERT().
179 @param Port The I/O port to read.
181 @return The value read.
192 ASSERT ((Port
& 3) == 0);
193 _ReadWriteBarrier ();
194 Value
= _inpd ((UINT16
)Port
);
195 _ReadWriteBarrier ();
200 Writes a 32-bit I/O port.
202 Writes the 32-bit I/O port specified by Port with the value specified by Value
203 and returns Value. This function must guarantee that all I/O read and write
204 operations are serialized.
206 If 32-bit I/O port operations are not supported, then ASSERT().
208 @param Port The I/O port to write.
209 @param Value The value to write to the I/O port.
211 @return The value written the I/O port.
221 ASSERT ((Port
& 3) == 0);
222 _ReadWriteBarrier ();
223 _outpd ((UINT16
)Port
, Value
);
224 _ReadWriteBarrier ();
230 Reads an 8-bit MMIO register.
232 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
233 returned. This function must guarantee that all MMIO read and write
234 operations are serialized.
236 If 8-bit MMIO register operations are not supported, then ASSERT().
238 @param Address The MMIO register to read.
240 @return The value read.
251 Value
= *(volatile UINT8
*)Address
;
256 Writes an 8-bit MMIO register.
258 Writes the 8-bit MMIO register specified by Address with the value specified
259 by Value and returns Value. This function must guarantee that all MMIO read
260 and write operations are serialized.
262 If 8-bit MMIO register operations are not supported, then ASSERT().
264 @param Address The MMIO register to write.
265 @param Value The value to write to the MMIO register.
275 return *(volatile UINT8
*)Address
= Value
;
279 Reads a 16-bit MMIO register.
281 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
282 returned. This function must guarantee that all MMIO read and write
283 operations are serialized.
285 If 16-bit MMIO register operations are not supported, then ASSERT().
287 @param Address The MMIO register to read.
289 @return The value read.
300 ASSERT ((Address
& 1) == 0);
301 Value
= *(volatile UINT16
*)Address
;
306 Writes a 16-bit MMIO register.
308 Writes the 16-bit MMIO register specified by Address with the value specified
309 by Value and returns Value. This function must guarantee that all MMIO read
310 and write operations are serialized.
312 If 16-bit MMIO register operations are not supported, then ASSERT().
314 @param Address The MMIO register to write.
315 @param Value The value to write to the MMIO register.
325 ASSERT ((Address
& 1) == 0);
326 return *(volatile UINT16
*)Address
= Value
;
330 Reads a 32-bit MMIO register.
332 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
333 returned. This function must guarantee that all MMIO read and write
334 operations are serialized.
336 If 32-bit MMIO register operations are not supported, then ASSERT().
338 @param Address The MMIO register to read.
340 @return The value read.
351 ASSERT ((Address
& 3) == 0);
352 Value
= *(volatile UINT32
*)Address
;
357 Writes a 32-bit MMIO register.
359 Writes the 32-bit MMIO register specified by Address with the value specified
360 by Value and returns Value. This function must guarantee that all MMIO read
361 and write operations are serialized.
363 If 32-bit MMIO register operations are not supported, then ASSERT().
365 @param Address The MMIO register to write.
366 @param Value The value to write to the MMIO register.
376 ASSERT ((Address
& 3) == 0);
377 return *(volatile UINT32
*)Address
= Value
;
381 Reads a 64-bit MMIO register.
383 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
384 returned. This function must guarantee that all MMIO read and write
385 operations are serialized.
387 If 64-bit MMIO register operations are not supported, then ASSERT().
389 @param Address The MMIO register to read.
391 @return The value read.
402 ASSERT ((Address
& 7) == 0);
403 Value
= *(volatile UINT64
*)Address
;
408 Writes a 64-bit MMIO register.
410 Writes the 64-bit MMIO register specified by Address with the value specified
411 by Value and returns Value. This function must guarantee that all MMIO read
412 and write operations are serialized.
414 If 64-bit MMIO register operations are not supported, then ASSERT().
416 @param Address The MMIO register to write.
417 @param Value The value to write to the MMIO register.
427 ASSERT ((Address
& 7) == 0);
428 return *(volatile UINT64
*)Address
= Value
;