]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibMsc.c
35854c6ccd9a3eb42753202d9c244ee68a4055a3
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.
20 Module Name: IoLibMsc.c
26 // Include common header file for this module.
28 #include "CommonHeader.h"
31 // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics
33 int _inp (unsigned short port
);
34 unsigned short _inpw (unsigned short port
);
35 unsigned long _inpd (unsigned short port
);
36 int _outp (unsigned short port
, int databyte
);
37 unsigned short _outpw (unsigned short port
, unsigned short dataword
);
38 unsigned long _outpd (unsigned short port
, unsigned long dataword
);
39 void _ReadWriteBarrier (void);
41 #pragma intrinsic(_inp)
42 #pragma intrinsic(_inpw)
43 #pragma intrinsic(_inpd)
44 #pragma intrinsic(_outp)
45 #pragma intrinsic(_outpw)
46 #pragma intrinsic(_outpd)
47 #pragma intrinsic(_ReadWriteBarrier)
50 // _ReadWriteBarrier() forces memory reads and writes to complete at the point
51 // in the call. This is only a hint to the compiler and does emit code.
52 // In past versions of the compiler, _ReadWriteBarrier was enforced only
53 // locally and did not affect functions up the call tree. In Visual C++
54 // 2005, _ReadWriteBarrier is enforced all the way up the call tree.
58 Reads an 8-bit I/O port.
60 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
61 This function must guarantee that all I/O read and write operations are
64 If 8-bit I/O port operations are not supported, then ASSERT().
66 @param Port The I/O port to read.
68 @return The value read.
80 Value
= (UINT8
)_inp ((UINT16
)Port
);
86 Writes an 8-bit I/O port.
88 Writes the 8-bit I/O port specified by Port with the value specified by Value
89 and returns Value. This function must guarantee that all I/O read and write
90 operations are serialized.
92 If 8-bit I/O port operations are not supported, then ASSERT().
94 @param Port The I/O port to write.
95 @param Value The value to write to the I/O port.
97 @return The value written the I/O port.
107 _ReadWriteBarrier ();
108 (UINT8
)_outp ((UINT16
)Port
, Value
);
109 _ReadWriteBarrier ();
114 Reads a 16-bit I/O port.
116 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
117 This function must guarantee that all I/O read and write operations are
120 If 16-bit I/O port operations are not supported, then ASSERT().
122 @param Port The I/O port to read.
124 @return The value read.
135 ASSERT ((Port
& 1) == 0);
136 _ReadWriteBarrier ();
137 Value
= _inpw ((UINT16
)Port
);
138 _ReadWriteBarrier ();
143 Writes a 16-bit I/O port.
145 Writes the 16-bit I/O port specified by Port with the value specified by Value
146 and returns Value. This function must guarantee that all I/O read and write
147 operations are serialized.
149 If 16-bit I/O port operations are not supported, then ASSERT().
151 @param Port The I/O port to write.
152 @param Value The value to write to the I/O port.
154 @return The value written the I/O port.
164 ASSERT ((Port
& 1) == 0);
165 _ReadWriteBarrier ();
166 _outpw ((UINT16
)Port
, Value
);
167 _ReadWriteBarrier ();
172 Reads a 32-bit I/O port.
174 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
175 This function must guarantee that all I/O read and write operations are
178 If 32-bit I/O port operations are not supported, then ASSERT().
180 @param Port The I/O port to read.
182 @return The value read.
193 ASSERT ((Port
& 3) == 0);
194 _ReadWriteBarrier ();
195 Value
= _inpd ((UINT16
)Port
);
196 _ReadWriteBarrier ();
201 Writes a 32-bit I/O port.
203 Writes the 32-bit I/O port specified by Port with the value specified by Value
204 and returns Value. This function must guarantee that all I/O read and write
205 operations are serialized.
207 If 32-bit I/O port operations are not supported, then ASSERT().
209 @param Port The I/O port to write.
210 @param Value The value to write to the I/O port.
212 @return The value written the I/O port.
222 ASSERT ((Port
& 3) == 0);
223 _ReadWriteBarrier ();
224 _outpd ((UINT16
)Port
, Value
);
225 _ReadWriteBarrier ();
231 Reads an 8-bit MMIO register.
233 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
234 returned. This function must guarantee that all MMIO read and write
235 operations are serialized.
237 If 8-bit MMIO register operations are not supported, then ASSERT().
239 @param Address The MMIO register to read.
241 @return The value read.
252 Value
= *(volatile UINT8
*)Address
;
257 Writes an 8-bit MMIO register.
259 Writes the 8-bit MMIO register specified by Address with the value specified
260 by Value and returns Value. This function must guarantee that all MMIO read
261 and write operations are serialized.
263 If 8-bit MMIO register operations are not supported, then ASSERT().
265 @param Address The MMIO register to write.
266 @param Value The value to write to the MMIO register.
276 return *(volatile UINT8
*)Address
= Value
;
280 Reads a 16-bit MMIO register.
282 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
283 returned. This function must guarantee that all MMIO read and write
284 operations are serialized.
286 If 16-bit MMIO register operations are not supported, then ASSERT().
288 @param Address The MMIO register to read.
290 @return The value read.
301 ASSERT ((Address
& 1) == 0);
302 Value
= *(volatile UINT16
*)Address
;
307 Writes a 16-bit MMIO register.
309 Writes the 16-bit MMIO register specified by Address with the value specified
310 by Value and returns Value. This function must guarantee that all MMIO read
311 and write operations are serialized.
313 If 16-bit MMIO register operations are not supported, then ASSERT().
315 @param Address The MMIO register to write.
316 @param Value The value to write to the MMIO register.
326 ASSERT ((Address
& 1) == 0);
327 return *(volatile UINT16
*)Address
= Value
;
331 Reads a 32-bit MMIO register.
333 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
334 returned. This function must guarantee that all MMIO read and write
335 operations are serialized.
337 If 32-bit MMIO register operations are not supported, then ASSERT().
339 @param Address The MMIO register to read.
341 @return The value read.
352 ASSERT ((Address
& 3) == 0);
353 Value
= *(volatile UINT32
*)Address
;
358 Writes a 32-bit MMIO register.
360 Writes the 32-bit MMIO register specified by Address with the value specified
361 by Value and returns Value. This function must guarantee that all MMIO read
362 and write operations are serialized.
364 If 32-bit MMIO register operations are not supported, then ASSERT().
366 @param Address The MMIO register to write.
367 @param Value The value to write to the MMIO register.
377 ASSERT ((Address
& 3) == 0);
378 return *(volatile UINT32
*)Address
= Value
;
382 Reads a 64-bit MMIO register.
384 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
385 returned. This function must guarantee that all MMIO read and write
386 operations are serialized.
388 If 64-bit MMIO register operations are not supported, then ASSERT().
390 @param Address The MMIO register to read.
392 @return The value read.
403 ASSERT ((Address
& 7) == 0);
404 Value
= *(volatile UINT64
*)Address
;
409 Writes a 64-bit MMIO register.
411 Writes the 64-bit MMIO register specified by Address with the value specified
412 by Value and returns Value. This function must guarantee that all MMIO read
413 and write operations are serialized.
415 If 64-bit MMIO register operations are not supported, then ASSERT().
417 @param Address The MMIO register to write.
418 @param Value The value to write to the MMIO register.
428 ASSERT ((Address
& 7) == 0);
429 return *(volatile UINT64
*)Address
= Value
;