]>
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, 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
28 // 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.
75 return (UINT8
)_inp ((UINT16
)Port
);
79 Writes an 8-bit I/O port.
81 Writes the 8-bit I/O port specified by Port with the value specified by Value
82 and returns Value. This function must guarantee that all I/O read and write
83 operations are serialized.
85 If 8-bit I/O port operations are not supported, then ASSERT().
87 @param Port The I/O port to write.
88 @param Value The value to write to the I/O port.
90 @return The value written the I/O port.
100 _ReadWriteBarrier ();
101 return (UINT8
)_outp ((UINT16
)Port
, Value
);
105 Reads a 16-bit I/O port.
107 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
108 This function must guarantee that all I/O read and write operations are
111 If 16-bit I/O port operations are not supported, then ASSERT().
113 @param Port The I/O port to read.
115 @return The value read.
124 ASSERT ((Port
& 1) == 0);
125 _ReadWriteBarrier ();
126 return _inpw((UINT16
)Port
);
130 Writes a 16-bit I/O port.
132 Writes the 16-bit I/O port specified by Port with the value specified by Value
133 and returns Value. This function must guarantee that all I/O read and write
134 operations are serialized.
136 If 16-bit I/O port operations are not supported, then ASSERT().
138 @param Port The I/O port to write.
139 @param Value The value to write to the I/O port.
141 @return The value written the I/O port.
151 ASSERT ((Port
& 1) == 0);
152 _ReadWriteBarrier ();
153 return _outpw ((UINT16
)Port
, Value
);
157 Reads a 32-bit I/O port.
159 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
160 This function must guarantee that all I/O read and write operations are
163 If 32-bit I/O port operations are not supported, then ASSERT().
165 @param Port The I/O port to read.
167 @return The value read.
176 ASSERT ((Port
& 3) == 0);
177 _ReadWriteBarrier ();
178 return _inpd((UINT16
)Port
);
182 Writes a 32-bit I/O port.
184 Writes the 32-bit I/O port specified by Port with the value specified by Value
185 and returns Value. This function must guarantee that all I/O read and write
186 operations are serialized.
188 If 32-bit I/O port operations are not supported, then ASSERT().
190 @param Port The I/O port to write.
191 @param Value The value to write to the I/O port.
193 @return The value written the I/O port.
203 ASSERT ((Port
& 3) == 0);
204 _ReadWriteBarrier ();
205 return _outpd ((UINT16
)Port
, Value
);
210 Reads an 8-bit MMIO register.
212 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
213 returned. This function must guarantee that all MMIO read and write
214 operations are serialized.
216 If 8-bit MMIO register operations are not supported, then ASSERT().
218 @param Address The MMIO register to read.
220 @return The value read.
229 _ReadWriteBarrier ();
230 return *(volatile UINT8
*)Address
;
234 Writes an 8-bit MMIO register.
236 Writes the 8-bit MMIO register specified by Address with the value specified
237 by Value and returns Value. This function must guarantee that all MMIO read
238 and write operations are serialized.
240 If 8-bit MMIO register operations are not supported, then ASSERT().
242 @param Address The MMIO register to write.
243 @param Value The value to write to the MMIO register.
253 _ReadWriteBarrier ();
254 return *(volatile UINT8
*)Address
= Value
;
258 Reads a 16-bit MMIO register.
260 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
261 returned. This function must guarantee that all MMIO read and write
262 operations are serialized.
264 If 16-bit MMIO register operations are not supported, then ASSERT().
266 @param Address The MMIO register to read.
268 @return The value read.
277 ASSERT ((Address
& 1) == 0);
278 _ReadWriteBarrier ();
279 return *(volatile UINT16
*)Address
;
283 Writes a 16-bit MMIO register.
285 Writes the 16-bit MMIO register specified by Address with the value specified
286 by Value and returns Value. This function must guarantee that all MMIO read
287 and write operations are serialized.
289 If 16-bit MMIO register operations are not supported, then ASSERT().
291 @param Address The MMIO register to write.
292 @param Value The value to write to the MMIO register.
302 ASSERT ((Address
& 1) == 0);
303 _ReadWriteBarrier ();
304 return *(volatile UINT16
*)Address
= Value
;
308 Reads a 32-bit MMIO register.
310 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
311 returned. This function must guarantee that all MMIO read and write
312 operations are serialized.
314 If 32-bit MMIO register operations are not supported, then ASSERT().
316 @param Address The MMIO register to read.
318 @return The value read.
327 ASSERT ((Address
& 3) == 0);
328 _ReadWriteBarrier ();
329 return *(volatile UINT32
*)Address
;
333 Writes a 32-bit MMIO register.
335 Writes the 32-bit MMIO register specified by Address with the value specified
336 by Value and returns Value. This function must guarantee that all MMIO read
337 and write operations are serialized.
339 If 32-bit MMIO register operations are not supported, then ASSERT().
341 @param Address The MMIO register to write.
342 @param Value The value to write to the MMIO register.
352 ASSERT ((Address
& 3) == 0);
353 _ReadWriteBarrier ();
354 return *(volatile UINT32
*)Address
= Value
;
358 Reads a 64-bit MMIO register.
360 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
361 returned. This function must guarantee that all MMIO read and write
362 operations are serialized.
364 If 64-bit MMIO register operations are not supported, then ASSERT().
366 @param Address The MMIO register to read.
368 @return The value read.
377 ASSERT ((Address
& 7) == 0);
378 _ReadWriteBarrier ();
379 return *(volatile UINT64
*)Address
;
383 Writes a 64-bit MMIO register.
385 Writes the 64-bit MMIO register specified by Address with the value specified
386 by Value and returns Value. This function must guarantee that all MMIO read
387 and write operations are serialized.
389 If 64-bit MMIO register operations are not supported, then ASSERT().
391 @param Address The MMIO register to write.
392 @param Value The value to write to the MMIO register.
402 ASSERT ((Address
& 7) == 0);
403 _ReadWriteBarrier ();
404 return *(volatile UINT64
*)Address
= Value
;