]>
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 "BaseIoLibIntrinsicInternal.h"
27 // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.
30 int _inp (unsigned short port
);
31 unsigned short _inpw (unsigned short port
);
32 unsigned long _inpd (unsigned short port
);
33 int _outp (unsigned short port
, int databyte
);
34 unsigned short _outpw (unsigned short port
, unsigned short dataword
);
35 unsigned long _outpd (unsigned short port
, unsigned long dataword
);
36 void _ReadWriteBarrier (void);
38 #pragma intrinsic(_inp)
39 #pragma intrinsic(_inpw)
40 #pragma intrinsic(_inpd)
41 #pragma intrinsic(_outp)
42 #pragma intrinsic(_outpw)
43 #pragma intrinsic(_outpd)
44 #pragma intrinsic(_ReadWriteBarrier)
47 // _ReadWriteBarrier() forces memory reads and writes to complete at the point
48 // in the call. This is only a hint to the compiler and does emit code.
49 // In past versions of the compiler, _ReadWriteBarrier was enforced only
50 // locally and did not affect functions up the call tree. In Visual C++
51 // 2005, _ReadWriteBarrier is enforced all the way up the call tree.
55 Reads an 8-bit I/O port.
57 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
58 This function must guarantee that all I/O read and write operations are
61 If 8-bit I/O port operations are not supported, then ASSERT().
63 @param Port The I/O port to read.
65 @return The value read from Port.
77 Value
= (UINT8
)_inp ((UINT16
)Port
);
83 Writes an 8-bit I/O port.
85 Writes the 8-bit I/O port specified by Port with the value specified by Value
86 and returns Value. This function must guarantee that all I/O read and write
87 operations are serialized.
89 If 8-bit I/O port operations are not supported, then ASSERT().
91 @param Port The I/O port to write.
92 @param Value The value to write to the I/O port.
94 @return The value written the I/O port.
104 _ReadWriteBarrier ();
105 (UINT8
)_outp ((UINT16
)Port
, Value
);
106 _ReadWriteBarrier ();
111 Reads a 16-bit I/O port.
113 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
114 This function must guarantee that all I/O read and write operations are
117 If 16-bit I/O port operations are not supported, then ASSERT().
119 @param Port The I/O port to read.
121 @return The value read from Port.
132 ASSERT ((Port
& 1) == 0);
133 _ReadWriteBarrier ();
134 Value
= _inpw ((UINT16
)Port
);
135 _ReadWriteBarrier ();
140 Writes a 16-bit I/O port.
142 Writes the 16-bit I/O port specified by Port with the value specified by Value
143 and returns Value. This function must guarantee that all I/O read and write
144 operations are serialized.
146 If 16-bit I/O port operations are not supported, then ASSERT().
148 @param Port The I/O port to write.
149 @param Value The value to write to the I/O port.
151 @return The value written the I/O port.
161 ASSERT ((Port
& 1) == 0);
162 _ReadWriteBarrier ();
163 _outpw ((UINT16
)Port
, Value
);
164 _ReadWriteBarrier ();
169 Reads a 32-bit I/O port.
171 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
172 This function must guarantee that all I/O read and write operations are
175 If 32-bit I/O port operations are not supported, then ASSERT().
177 @param Port The I/O port to read.
179 @return The value read from Port.
190 ASSERT ((Port
& 3) == 0);
191 _ReadWriteBarrier ();
192 Value
= _inpd ((UINT16
)Port
);
193 _ReadWriteBarrier ();
198 Writes a 32-bit I/O port.
200 Writes the 32-bit I/O port specified by Port with the value specified by Value
201 and returns Value. This function must guarantee that all I/O read and write
202 operations are serialized.
204 If 32-bit I/O port operations are not supported, then ASSERT().
206 @param Port The I/O port to write.
207 @param Value The value to write to the I/O port.
209 @return The value written the I/O port.
219 ASSERT ((Port
& 3) == 0);
220 _ReadWriteBarrier ();
221 _outpd ((UINT16
)Port
, Value
);
222 _ReadWriteBarrier ();
228 Reads an 8-bit MMIO register.
230 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
231 returned. This function must guarantee that all MMIO read and write
232 operations are serialized.
234 If 8-bit MMIO register operations are not supported, then ASSERT().
236 @param Address The MMIO register to read.
238 @return The value read from Address.
249 Value
= *(volatile UINT8
*)Address
;
254 Writes an 8-bit MMIO register.
256 Writes the 8-bit MMIO register specified by Address with the value specified
257 by Value and returns Value. This function must guarantee that all MMIO read
258 and write operations are serialized.
260 If 8-bit MMIO register operations are not supported, then ASSERT().
262 @param Address The MMIO register to write.
263 @param Value The value to write to the MMIO register.
265 @return The value written to the Mmio. It equals to the input
266 Value instead of the actual value read back from the
277 return *(volatile UINT8
*)Address
= Value
;
281 Reads a 16-bit MMIO register.
283 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
284 returned. This function must guarantee that all MMIO read and write
285 operations are serialized.
287 If 16-bit MMIO register operations are not supported, then ASSERT().
289 @param Address The MMIO register to read.
291 @return The value read from Address.
302 ASSERT ((Address
& 1) == 0);
303 Value
= *(volatile UINT16
*)Address
;
308 Writes a 16-bit MMIO register.
310 Writes the 16-bit MMIO register specified by Address with the value specified
311 by Value and returns Value. This function must guarantee that all MMIO read
312 and write operations are serialized.
314 If 16-bit MMIO register operations are not supported, then ASSERT().
316 @param Address The MMIO register to write.
317 @param Value The value to write to the MMIO register.
319 @return The value read from the Mmio after wrote specified
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 from Address.
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.
373 @return The value written to the Mmio. It equals to the input
374 Value instead of the actual value read back from the
385 ASSERT ((Address
& 3) == 0);
386 return *(volatile UINT32
*)Address
= Value
;
390 Reads a 64-bit MMIO register.
392 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
393 returned. This function must guarantee that all MMIO read and write
394 operations are serialized.
396 If 64-bit MMIO register operations are not supported, then ASSERT().
398 @param Address The MMIO register to read.
400 @return The value read from Address.
411 ASSERT ((Address
& 7) == 0);
412 Value
= *(volatile UINT64
*)Address
;
417 Writes a 64-bit MMIO register.
419 Writes the 64-bit MMIO register specified by Address with the value specified
420 by Value and returns Value. This function must guarantee that all MMIO read
421 and write operations are serialized.
423 If 64-bit MMIO register operations are not supported, then ASSERT().
425 @param Address The MMIO register to write.
426 @param Value The value to write to the MMIO register.
428 @return The value written to the Mmio. It equals to the input
429 Value instead of the actual value read back from the
440 ASSERT ((Address
& 7) == 0);
441 return *(volatile UINT64
*)Address
= Value
;