]>
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.
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().
118 If Port is not aligned on a 16-bit boundary, then ASSERT().
120 @param Port The I/O port to read.
122 @return The value read.
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().
148 If Port is not aligned on a 16-bit boundary, 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().
178 If Port is not aligned on a 32-bit boundary, 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().
208 If Port is not aligned on a 32-bit boundary, then ASSERT().
210 @param Port The I/O port to write.
211 @param Value The value to write to the I/O port.
213 @return The value written the I/O port.
223 ASSERT ((Port
& 3) == 0);
224 _ReadWriteBarrier ();
225 _outpd ((UINT16
)Port
, Value
);
226 _ReadWriteBarrier ();
232 Reads an 8-bit MMIO register.
234 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
235 returned. This function must guarantee that all MMIO read and write
236 operations are serialized.
238 If 8-bit MMIO register operations are not supported, then ASSERT().
240 @param Address The MMIO register to read.
242 @return The value read.
253 Value
= *(volatile UINT8
*)Address
;
258 Writes an 8-bit MMIO register.
260 Writes the 8-bit MMIO register specified by Address with the value specified
261 by Value and returns Value. This function must guarantee that all MMIO read
262 and write operations are serialized.
264 If 8-bit MMIO register operations are not supported, then ASSERT().
266 @param Address The MMIO register to write.
267 @param Value The value to write to the MMIO register.
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().
290 If Address is not aligned on a 16-bit boundary, 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().
318 If Address is not aligned on a 16-bit boundary, then ASSERT().
320 @param Address The MMIO register to write.
321 @param Value The value to write to the MMIO register.
333 ASSERT ((Address
& 1) == 0);
334 return *(volatile UINT16
*)Address
= Value
;
338 Reads a 32-bit MMIO register.
340 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
341 returned. This function must guarantee that all MMIO read and write
342 operations are serialized.
344 If 32-bit MMIO register operations are not supported, then ASSERT().
345 If Address is not aligned on a 32-bit boundary, then ASSERT().
347 @param Address The MMIO register to read.
349 @return The value read.
360 ASSERT ((Address
& 3) == 0);
361 Value
= *(volatile UINT32
*)Address
;
366 Writes a 32-bit MMIO register.
368 Writes the 32-bit MMIO register specified by Address with the value specified
369 by Value and returns Value. This function must guarantee that all MMIO read
370 and write operations are serialized.
372 If 32-bit MMIO register operations are not supported, then ASSERT().
373 If Address is not aligned on a 32-bit boundary, then ASSERT().
375 @param Address The MMIO register to write.
376 @param Value The value to write to the MMIO register.
388 ASSERT ((Address
& 3) == 0);
389 return *(volatile UINT32
*)Address
= Value
;
393 Reads a 64-bit MMIO register.
395 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
396 returned. This function must guarantee that all MMIO read and write
397 operations are serialized.
399 If 64-bit MMIO register operations are not supported, then ASSERT().
400 If Address is not aligned on a 64-bit boundary, then ASSERT().
402 @param Address The MMIO register to read.
404 @return The value read.
415 ASSERT ((Address
& 7) == 0);
416 Value
= *(volatile UINT64
*)Address
;
421 Writes a 64-bit MMIO register.
423 Writes the 64-bit MMIO register specified by Address with the value specified
424 by Value and returns Value. This function must guarantee that all MMIO read
425 and write operations are serialized.
427 If 64-bit MMIO register operations are not supported, then ASSERT().
428 If Address is not aligned on a 64-bit boundary, then ASSERT().
430 @param Address The MMIO register to write.
431 @param Value The value to write to the MMIO register.
441 ASSERT ((Address
& 7) == 0);
442 return *(volatile UINT64
*)Address
= Value
;