]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibMsc.c
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 from Port.
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 from Port.
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 from Port.
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 from Address.
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.
266 @return The value written to the Mmio. It equals to the input
267 Value instead of the actual value read back from the
278 return *(volatile UINT8
*)Address
= Value
;
282 Reads a 16-bit MMIO register.
284 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
285 returned. This function must guarantee that all MMIO read and write
286 operations are serialized.
288 If 16-bit MMIO register operations are not supported, then ASSERT().
290 @param Address The MMIO register to read.
292 @return The value read from Address.
303 ASSERT ((Address
& 1) == 0);
304 Value
= *(volatile UINT16
*)Address
;
309 Writes a 16-bit MMIO register.
311 Writes the 16-bit MMIO register specified by Address with the value specified
312 by Value and returns Value. This function must guarantee that all MMIO read
313 and write operations are serialized.
315 If 16-bit MMIO register operations are not supported, then ASSERT().
317 @param Address The MMIO register to write.
318 @param Value The value to write to the MMIO register.
320 @return The value read from the Mmio after wrote specified
331 ASSERT ((Address
& 1) == 0);
332 return *(volatile UINT16
*)Address
= Value
;
336 Reads a 32-bit MMIO register.
338 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
339 returned. This function must guarantee that all MMIO read and write
340 operations are serialized.
342 If 32-bit MMIO register operations are not supported, then ASSERT().
344 @param Address The MMIO register to read.
346 @return The value read from Address.
357 ASSERT ((Address
& 3) == 0);
358 Value
= *(volatile UINT32
*)Address
;
363 Writes a 32-bit MMIO register.
365 Writes the 32-bit MMIO register specified by Address with the value specified
366 by Value and returns Value. This function must guarantee that all MMIO read
367 and write operations are serialized.
369 If 32-bit MMIO register operations are not supported, then ASSERT().
371 @param Address The MMIO register to write.
372 @param Value The value to write to the MMIO register.
374 @return The value written to the Mmio. It equals to the input
375 Value instead of the actual value read back from the
386 ASSERT ((Address
& 3) == 0);
387 return *(volatile UINT32
*)Address
= Value
;
391 Reads a 64-bit MMIO register.
393 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
394 returned. This function must guarantee that all MMIO read and write
395 operations are serialized.
397 If 64-bit MMIO register operations are not supported, then ASSERT().
399 @param Address The MMIO register to read.
401 @return The value read from Address.
412 ASSERT ((Address
& 7) == 0);
413 Value
= *(volatile UINT64
*)Address
;
418 Writes a 64-bit MMIO register.
420 Writes the 64-bit MMIO register specified by Address with the value specified
421 by Value and returns Value. This function must guarantee that all MMIO read
422 and write operations are serialized.
424 If 64-bit MMIO register operations are not supported, then ASSERT().
426 @param Address The MMIO register to write.
427 @param Value The value to write to the MMIO register.
429 @return The value written to the Mmio. It equals to the input
430 Value instead of the actual value read back from the
441 ASSERT ((Address
& 7) == 0);
442 return *(volatile UINT64
*)Address
= Value
;