]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseIoLibIntrinsic/IoLibMsc.c
3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 I/O Library. This file has compiler specifics for Microsft C as there is no
20 ANSI C standard for doing IO.
22 MSC - uses intrinsic functions and the optimize will remove the function call
25 We don't advocate putting compiler specifics in libraries or drivers but there
26 is no other way to make this work.
30 #include "EdkIIGlueBase.h"
35 // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics
37 int _inp (unsigned short port
);
38 unsigned short _inpw (unsigned short port
);
39 unsigned long _inpd (unsigned short port
);
40 int _outp (unsigned short port
, int databyte
);
41 unsigned short _outpw (unsigned short port
, unsigned short dataword
);
42 unsigned long _outpd (unsigned short port
, unsigned long dataword
);
43 void _ReadWriteBarrier (void);
45 #pragma intrinsic(_inp)
46 #pragma intrinsic(_inpw)
47 #pragma intrinsic(_inpd)
48 #pragma intrinsic(_outp)
49 #pragma intrinsic(_outpw)
50 #pragma intrinsic(_outpd)
51 #pragma intrinsic(_ReadWriteBarrier)
54 // _ReadWriteBarrier() forces memory reads and writes to complete at the point
55 // in the call. This is only a hint to the compiler and does emit code.
56 // In past versions of the compiler, _ReadWriteBarrier was enforced only
57 // locally and did not affect functions up the call tree. In Visual C++
58 // 2005, _ReadWriteBarrier is enforced all the way up the call tree.
62 Reads an 8-bit I/O port.
64 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
65 This function must guarantee that all I/O read and write operations are
68 If 8-bit I/O port operations are not supported, then ASSERT().
70 @param Port The I/O port to read.
72 @return The value read.
84 Value
= (UINT8
)_inp ((UINT16
)Port
);
90 Writes an 8-bit I/O port.
92 Writes the 8-bit I/O port specified by Port with the value specified by Value
93 and returns Value. This function must guarantee that all I/O read and write
94 operations are serialized.
96 If 8-bit I/O port operations are not supported, then ASSERT().
98 @param Port The I/O port to write.
99 @param Value The value to write to the I/O port.
101 @return The value written the I/O port.
111 _ReadWriteBarrier ();
112 (UINT8
)_outp ((UINT16
)Port
, Value
);
113 _ReadWriteBarrier ();
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().
126 @param Port The I/O port to read.
128 @return The value read.
139 ASSERT ((Port
& 1) == 0);
140 _ReadWriteBarrier ();
141 Value
= _inpw ((UINT16
)Port
);
142 _ReadWriteBarrier ();
147 Writes a 16-bit I/O port.
149 Writes the 16-bit I/O port specified by Port with the value specified by Value
150 and returns Value. This function must guarantee that all I/O read and write
151 operations are serialized.
153 If 16-bit I/O port operations are not supported, then ASSERT().
155 @param Port The I/O port to write.
156 @param Value The value to write to the I/O port.
158 @return The value written the I/O port.
168 ASSERT ((Port
& 1) == 0);
169 _ReadWriteBarrier ();
170 _outpw ((UINT16
)Port
, Value
);
171 _ReadWriteBarrier ();
176 Reads a 32-bit I/O port.
178 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
179 This function must guarantee that all I/O read and write operations are
182 If 32-bit I/O port operations are not supported, then ASSERT().
184 @param Port The I/O port to read.
186 @return The value read.
197 ASSERT ((Port
& 3) == 0);
198 _ReadWriteBarrier ();
199 Value
= _inpd ((UINT16
)Port
);
200 _ReadWriteBarrier ();
205 Writes a 32-bit I/O port.
207 Writes the 32-bit I/O port specified by Port with the value specified by Value
208 and returns Value. This function must guarantee that all I/O read and write
209 operations are serialized.
211 If 32-bit I/O port operations are not supported, then ASSERT().
213 @param Port The I/O port to write.
214 @param Value The value to write to the I/O port.
216 @return The value written the I/O port.
226 ASSERT ((Port
& 3) == 0);
227 _ReadWriteBarrier ();
228 _outpd ((UINT16
)Port
, Value
);
229 _ReadWriteBarrier ();
235 Reads an 8-bit MMIO register.
237 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
238 returned. This function must guarantee that all MMIO read and write
239 operations are serialized.
241 If 8-bit MMIO register operations are not supported, then ASSERT().
243 @param Address The MMIO register to read.
245 @return The value read.
256 Value
= *(volatile UINT8
*)Address
;
261 Writes an 8-bit MMIO register.
263 Writes the 8-bit MMIO register specified by Address with the value specified
264 by Value and returns Value. This function must guarantee that all MMIO read
265 and write operations are serialized.
267 If 8-bit MMIO register operations are not supported, then ASSERT().
269 @param Address The MMIO register to write.
270 @param Value The value to write to the MMIO register.
280 return *(volatile UINT8
*)Address
= Value
;
284 Reads a 16-bit MMIO register.
286 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
287 returned. This function must guarantee that all MMIO read and write
288 operations are serialized.
290 If 16-bit MMIO register operations are not supported, then ASSERT().
292 @param Address The MMIO register to read.
294 @return The value read.
305 ASSERT ((Address
& 1) == 0);
306 Value
= *(volatile UINT16
*)Address
;
311 Writes a 16-bit MMIO register.
313 Writes the 16-bit MMIO register specified by Address with the value specified
314 by Value and returns Value. This function must guarantee that all MMIO read
315 and write operations are serialized.
317 If 16-bit MMIO register operations are not supported, then ASSERT().
319 @param Address The MMIO register to write.
320 @param Value The value to write to the MMIO register.
330 ASSERT ((Address
& 1) == 0);
331 return *(volatile UINT16
*)Address
= Value
;
335 Reads a 32-bit MMIO register.
337 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
338 returned. This function must guarantee that all MMIO read and write
339 operations are serialized.
341 If 32-bit MMIO register operations are not supported, then ASSERT().
343 @param Address The MMIO register to read.
345 @return The value read.
356 ASSERT ((Address
& 3) == 0);
357 Value
= *(volatile UINT32
*)Address
;
362 Writes a 32-bit MMIO register.
364 Writes the 32-bit MMIO register specified by Address with the value specified
365 by Value and returns Value. This function must guarantee that all MMIO read
366 and write operations are serialized.
368 If 32-bit MMIO register operations are not supported, then ASSERT().
370 @param Address The MMIO register to write.
371 @param Value The value to write to the MMIO register.
381 ASSERT ((Address
& 3) == 0);
382 return *(volatile UINT32
*)Address
= Value
;
386 Reads a 64-bit MMIO register.
388 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
389 returned. This function must guarantee that all MMIO read and write
390 operations are serialized.
392 If 64-bit MMIO register operations are not supported, then ASSERT().
394 @param Address The MMIO register to read.
396 @return The value read.
407 ASSERT ((Address
& 7) == 0);
408 Value
= *(volatile UINT64
*)Address
;
413 Writes a 64-bit MMIO register.
415 Writes the 64-bit MMIO register specified by Address with the value specified
416 by Value and returns Value. This function must guarantee that all MMIO read
417 and write operations are serialized.
419 If 64-bit MMIO register operations are not supported, then ASSERT().
421 @param Address The MMIO register to write.
422 @param Value The value to write to the MMIO register.
432 ASSERT ((Address
& 7) == 0);
433 return *(volatile UINT64
*)Address
= Value
;