]>
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.
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.
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.
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.
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.
273 return *(volatile UINT8
*)Address
= Value
;
277 Reads a 16-bit MMIO register.
279 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
280 returned. This function must guarantee that all MMIO read and write
281 operations are serialized.
283 If 16-bit MMIO register operations are not supported, then ASSERT().
285 @param Address The MMIO register to read.
287 @return The value read.
298 ASSERT ((Address
& 1) == 0);
299 Value
= *(volatile UINT16
*)Address
;
304 Writes a 16-bit MMIO register.
306 Writes the 16-bit MMIO register specified by Address with the value specified
307 by Value and returns Value. This function must guarantee that all MMIO read
308 and write operations are serialized.
310 If 16-bit MMIO register operations are not supported, then ASSERT().
312 @param Address The MMIO register to write.
313 @param Value The value to write to the MMIO register.
323 ASSERT ((Address
& 1) == 0);
324 return *(volatile UINT16
*)Address
= Value
;
328 Reads a 32-bit MMIO register.
330 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
331 returned. This function must guarantee that all MMIO read and write
332 operations are serialized.
334 If 32-bit MMIO register operations are not supported, then ASSERT().
336 @param Address The MMIO register to read.
338 @return The value read.
349 ASSERT ((Address
& 3) == 0);
350 Value
= *(volatile UINT32
*)Address
;
355 Writes a 32-bit MMIO register.
357 Writes the 32-bit MMIO register specified by Address with the value specified
358 by Value and returns Value. This function must guarantee that all MMIO read
359 and write operations are serialized.
361 If 32-bit MMIO register operations are not supported, then ASSERT().
363 @param Address The MMIO register to write.
364 @param Value The value to write to the MMIO register.
374 ASSERT ((Address
& 3) == 0);
375 return *(volatile UINT32
*)Address
= Value
;
379 Reads a 64-bit MMIO register.
381 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
382 returned. This function must guarantee that all MMIO read and write
383 operations are serialized.
385 If 64-bit MMIO register operations are not supported, then ASSERT().
387 @param Address The MMIO register to read.
389 @return The value read.
400 ASSERT ((Address
& 7) == 0);
401 Value
= *(volatile UINT64
*)Address
;
406 Writes a 64-bit MMIO register.
408 Writes the 64-bit MMIO register specified by Address with the value specified
409 by Value and returns Value. This function must guarantee that all MMIO read
410 and write operations are serialized.
412 If 64-bit MMIO register operations are not supported, then ASSERT().
414 @param Address The MMIO register to write.
415 @param Value The value to write to the MMIO register.
425 ASSERT ((Address
& 7) == 0);
426 return *(volatile UINT64
*)Address
= Value
;