43c3b79eee3aa40d60a932086f33bc2deb45fbbd
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.
32 int _inp (unsigned short port
);
33 unsigned short _inpw (unsigned short port
);
34 unsigned long _inpd (unsigned short port
);
35 int _outp (unsigned short port
, int databyte
);
36 unsigned short _outpw (unsigned short port
, unsigned short dataword
);
37 unsigned long _outpd (unsigned short port
, unsigned long dataword
);
38 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 from Port.
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 from Port.
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 from Port.
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 from Address.
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.
267 @return The value written to the Mmio. It equals to the input
268 Value instead of the actual value read back from the
279 return *(volatile UINT8
*)Address
= Value
;
283 Reads a 16-bit MMIO register.
285 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
286 returned. This function must guarantee that all MMIO read and write
287 operations are serialized.
289 If 16-bit MMIO register operations are not supported, then ASSERT().
291 @param Address The MMIO register to read.
293 @return The value read from Address.
304 ASSERT ((Address
& 1) == 0);
305 Value
= *(volatile UINT16
*)Address
;
310 Writes a 16-bit MMIO register.
312 Writes the 16-bit MMIO register specified by Address with the value specified
313 by Value and returns Value. This function must guarantee that all MMIO read
314 and write operations are serialized.
316 If 16-bit MMIO register operations are not supported, then ASSERT().
318 @param Address The MMIO register to write.
319 @param Value The value to write to the MMIO register.
321 @return The value read from the Mmio after wrote specified
332 ASSERT ((Address
& 1) == 0);
333 return *(volatile UINT16
*)Address
= Value
;
337 Reads a 32-bit MMIO register.
339 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
340 returned. This function must guarantee that all MMIO read and write
341 operations are serialized.
343 If 32-bit MMIO register operations are not supported, then ASSERT().
345 @param Address The MMIO register to read.
347 @return The value read from Address.
358 ASSERT ((Address
& 3) == 0);
359 Value
= *(volatile UINT32
*)Address
;
364 Writes a 32-bit MMIO register.
366 Writes the 32-bit MMIO register specified by Address with the value specified
367 by Value and returns Value. This function must guarantee that all MMIO read
368 and write operations are serialized.
370 If 32-bit MMIO register operations are not supported, then ASSERT().
372 @param Address The MMIO register to write.
373 @param Value The value to write to the MMIO register.
375 @return The value written to the Mmio. It equals to the input
376 Value instead of the actual value read back from the
387 ASSERT ((Address
& 3) == 0);
388 return *(volatile UINT32
*)Address
= Value
;
392 Reads a 64-bit MMIO register.
394 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
395 returned. This function must guarantee that all MMIO read and write
396 operations are serialized.
398 If 64-bit MMIO register operations are not supported, then ASSERT().
400 @param Address The MMIO register to read.
402 @return The value read from Address.
413 ASSERT ((Address
& 7) == 0);
414 Value
= *(volatile UINT64
*)Address
;
419 Writes a 64-bit MMIO register.
421 Writes the 64-bit MMIO register specified by Address with the value specified
422 by Value and returns Value. This function must guarantee that all MMIO read
423 and write operations are serialized.
425 If 64-bit MMIO register operations are not supported, then ASSERT().
427 @param Address The MMIO register to write.
428 @param Value The value to write to the MMIO register.
430 @return The value written to the Mmio. It equals to the input
431 Value instead of the actual value read back from the
442 ASSERT ((Address
& 7) == 0);
443 return *(volatile UINT64
*)Address
= Value
;