]>
git.proxmox.com Git - mirror_edk2.git/blob - OldMdePkg/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.
20 Module Name: IoLibMsc.c
26 // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics
28 int _inp (unsigned short port
);
29 unsigned short _inpw (unsigned short port
);
30 unsigned long _inpd (unsigned short port
);
31 int _outp (unsigned short port
, int databyte
);
32 unsigned short _outpw (unsigned short port
, unsigned short dataword
);
33 unsigned long _outpd (unsigned short port
, unsigned long dataword
);
34 void _ReadWriteBarrier (void);
36 #pragma intrinsic(_inp)
37 #pragma intrinsic(_inpw)
38 #pragma intrinsic(_inpd)
39 #pragma intrinsic(_outp)
40 #pragma intrinsic(_outpw)
41 #pragma intrinsic(_outpd)
42 #pragma intrinsic(_ReadWriteBarrier)
45 // _ReadWriteBarrier() forces memory reads and writes to complete at the point
46 // in the call. This is only a hint to the compiler and does emit code.
47 // In past versions of the compiler, _ReadWriteBarrier was enforced only
48 // locally and did not affect functions up the call tree. In Visual C++
49 // 2005, _ReadWriteBarrier is enforced all the way up the call tree.
53 Reads an 8-bit I/O port.
55 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
56 This function must guarantee that all I/O read and write operations are
59 If 8-bit I/O port operations are not supported, then ASSERT().
61 @param Port The I/O port to read.
63 @return The value read.
75 Value
= (UINT8
)_inp ((UINT16
)Port
);
81 Writes an 8-bit I/O port.
83 Writes the 8-bit I/O port specified by Port with the value specified by Value
84 and returns Value. This function must guarantee that all I/O read and write
85 operations are serialized.
87 If 8-bit I/O port operations are not supported, then ASSERT().
89 @param Port The I/O port to write.
90 @param Value The value to write to the I/O port.
92 @return The value written the I/O port.
102 _ReadWriteBarrier ();
103 (UINT8
)_outp ((UINT16
)Port
, Value
);
104 _ReadWriteBarrier ();
109 Reads a 16-bit I/O port.
111 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
112 This function must guarantee that all I/O read and write operations are
115 If 16-bit I/O port operations are not supported, then ASSERT().
117 @param Port The I/O port to read.
119 @return The value read.
130 ASSERT ((Port
& 1) == 0);
131 _ReadWriteBarrier ();
132 Value
= _inpw ((UINT16
)Port
);
133 _ReadWriteBarrier ();
138 Writes a 16-bit I/O port.
140 Writes the 16-bit I/O port specified by Port with the value specified by Value
141 and returns Value. This function must guarantee that all I/O read and write
142 operations are serialized.
144 If 16-bit I/O port operations are not supported, then ASSERT().
146 @param Port The I/O port to write.
147 @param Value The value to write to the I/O port.
149 @return The value written the I/O port.
159 ASSERT ((Port
& 1) == 0);
160 _ReadWriteBarrier ();
161 _outpw ((UINT16
)Port
, Value
);
162 _ReadWriteBarrier ();
167 Reads a 32-bit I/O port.
169 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
170 This function must guarantee that all I/O read and write operations are
173 If 32-bit I/O port operations are not supported, then ASSERT().
175 @param Port The I/O port to read.
177 @return The value read.
188 ASSERT ((Port
& 3) == 0);
189 _ReadWriteBarrier ();
190 Value
= _inpd ((UINT16
)Port
);
191 _ReadWriteBarrier ();
196 Writes a 32-bit I/O port.
198 Writes the 32-bit I/O port specified by Port with the value specified by Value
199 and returns Value. This function must guarantee that all I/O read and write
200 operations are serialized.
202 If 32-bit I/O port operations are not supported, then ASSERT().
204 @param Port The I/O port to write.
205 @param Value The value to write to the I/O port.
207 @return The value written the I/O port.
217 ASSERT ((Port
& 3) == 0);
218 _ReadWriteBarrier ();
219 _outpd ((UINT16
)Port
, Value
);
220 _ReadWriteBarrier ();
226 Reads an 8-bit MMIO register.
228 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
229 returned. This function must guarantee that all MMIO read and write
230 operations are serialized.
232 If 8-bit MMIO register operations are not supported, then ASSERT().
234 @param Address The MMIO register to read.
236 @return The value read.
247 Value
= *(volatile UINT8
*)Address
;
252 Writes an 8-bit MMIO register.
254 Writes the 8-bit MMIO register specified by Address with the value specified
255 by Value and returns Value. This function must guarantee that all MMIO read
256 and write operations are serialized.
258 If 8-bit MMIO register operations are not supported, then ASSERT().
260 @param Address The MMIO register to write.
261 @param Value The value to write to the MMIO register.
271 return *(volatile UINT8
*)Address
= Value
;
275 Reads a 16-bit MMIO register.
277 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
278 returned. This function must guarantee that all MMIO read and write
279 operations are serialized.
281 If 16-bit MMIO register operations are not supported, then ASSERT().
283 @param Address The MMIO register to read.
285 @return The value read.
296 ASSERT ((Address
& 1) == 0);
297 Value
= *(volatile UINT16
*)Address
;
302 Writes a 16-bit MMIO register.
304 Writes the 16-bit MMIO register specified by Address with the value specified
305 by Value and returns Value. This function must guarantee that all MMIO read
306 and write operations are serialized.
308 If 16-bit MMIO register operations are not supported, then ASSERT().
310 @param Address The MMIO register to write.
311 @param Value The value to write to the MMIO register.
321 ASSERT ((Address
& 1) == 0);
322 return *(volatile UINT16
*)Address
= Value
;
326 Reads a 32-bit MMIO register.
328 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
329 returned. This function must guarantee that all MMIO read and write
330 operations are serialized.
332 If 32-bit MMIO register operations are not supported, then ASSERT().
334 @param Address The MMIO register to read.
336 @return The value read.
347 ASSERT ((Address
& 3) == 0);
348 Value
= *(volatile UINT32
*)Address
;
353 Writes a 32-bit MMIO register.
355 Writes the 32-bit MMIO register specified by Address with the value specified
356 by Value and returns Value. This function must guarantee that all MMIO read
357 and write operations are serialized.
359 If 32-bit MMIO register operations are not supported, then ASSERT().
361 @param Address The MMIO register to write.
362 @param Value The value to write to the MMIO register.
372 ASSERT ((Address
& 3) == 0);
373 return *(volatile UINT32
*)Address
= Value
;
377 Reads a 64-bit MMIO register.
379 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
380 returned. This function must guarantee that all MMIO read and write
381 operations are serialized.
383 If 64-bit MMIO register operations are not supported, then ASSERT().
385 @param Address The MMIO register to read.
387 @return The value read.
398 ASSERT ((Address
& 7) == 0);
399 Value
= *(volatile UINT64
*)Address
;
404 Writes a 64-bit MMIO register.
406 Writes the 64-bit MMIO register specified by Address with the value specified
407 by Value and returns Value. This function must guarantee that all MMIO read
408 and write operations are serialized.
410 If 64-bit MMIO register operations are not supported, then ASSERT().
412 @param Address The MMIO register to write.
413 @param Value The value to write to the MMIO register.
423 ASSERT ((Address
& 7) == 0);
424 return *(volatile UINT64
*)Address
= Value
;