]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibGcc.c
2 I/O Library. This file has compiler specifics for GCC as there is no
3 ANSI C standard for doing IO.
5 GCC - uses EFIAPI assembler. __asm__ calls GAS. __volatile__ makes sure the
6 compiler puts the assembler in this exact location. The complex GNUC
7 operations are not optimzed. It would be possible to also write these
10 We don't advocate putting compiler specifics in libraries or drivers but there
11 is no other way to make this work.
13 Copyright (c) 2006 - 2007, Intel Corporation<BR>
14 All rights reserved. This program and the accompanying materials
15 are licensed and made available under the terms and conditions of the BSD License
16 which accompanies this distribution. The full text of the license may be found at
17 http://opensource.org/licenses/bsd-license.php
19 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
20 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 // Include common header file for this module.
27 #include "BaseIoLibIntrinsicInternal.h"
30 Reads an 8-bit MMIO register.
32 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
33 returned. This function must guarantee that all MMIO read and write
34 operations are serialized.
36 If 8-bit MMIO register operations are not supported, then ASSERT().
38 @param Address The MMIO register to read.
40 @return The value read.
49 return *(volatile UINT8
*)Address
;
53 Writes an 8-bit MMIO register.
55 Writes the 8-bit MMIO register specified by Address with the value specified
56 by Value and returns Value. This function must guarantee that all MMIO read
57 and write operations are serialized.
59 If 8-bit MMIO register operations are not supported, then ASSERT().
61 @param Address The MMIO register to write.
62 @param Value The value to write to the MMIO register.
72 return *(volatile UINT8
*)Address
= Value
;
76 Reads a 16-bit MMIO register.
78 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
79 returned. This function must guarantee that all MMIO read and write
80 operations are serialized.
82 If 16-bit MMIO register operations are not supported, then ASSERT().
84 @param Address The MMIO register to read.
86 @return The value read.
95 ASSERT ((Address
& 1) == 0);
96 return *(volatile UINT16
*)Address
;
100 Writes a 16-bit MMIO register.
102 Writes the 16-bit MMIO register specified by Address with the value specified
103 by Value and returns Value. This function must guarantee that all MMIO read
104 and write operations are serialized.
106 If 16-bit MMIO register operations are not supported, then ASSERT().
108 @param Address The MMIO register to write.
109 @param Value The value to write to the MMIO register.
119 ASSERT ((Address
& 1) == 0);
120 return *(volatile UINT16
*)Address
= Value
;
124 Reads a 32-bit MMIO register.
126 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
127 returned. This function must guarantee that all MMIO read and write
128 operations are serialized.
130 If 32-bit MMIO register operations are not supported, then ASSERT().
132 @param Address The MMIO register to read.
134 @return The value read.
143 ASSERT ((Address
& 3) == 0);
144 return *(volatile UINT32
*)Address
;
148 Writes a 32-bit MMIO register.
150 Writes the 32-bit MMIO register specified by Address with the value specified
151 by Value and returns Value. This function must guarantee that all MMIO read
152 and write operations are serialized.
154 If 32-bit MMIO register operations are not supported, then ASSERT().
156 @param Address The MMIO register to write.
157 @param Value The value to write to the MMIO register.
167 ASSERT ((Address
& 3) == 0);
168 return *(volatile UINT32
*)Address
= Value
;
172 Reads a 64-bit MMIO register.
174 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
175 returned. This function must guarantee that all MMIO read and write
176 operations are serialized.
178 If 64-bit MMIO register operations are not supported, then ASSERT().
180 @param Address The MMIO register to read.
182 @return The value read.
191 ASSERT ((Address
& 7) == 0);
192 return *(volatile UINT64
*)Address
;
196 Writes a 64-bit MMIO register.
198 Writes the 64-bit MMIO register specified by Address with the value specified
199 by Value and returns Value. This function must guarantee that all MMIO read
200 and write operations are serialized.
202 If 64-bit MMIO register operations are not supported, then ASSERT().
204 @param Address The MMIO register to write.
205 @param Value The value to write to the MMIO register.
215 ASSERT ((Address
& 7) == 0);
216 return *(volatile UINT64
*)Address
= Value
;
222 Reads an 8-bit I/O port.
224 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
225 This function must guarantee that all I/O read and write operations are
228 If 8-bit I/O port operations are not supported, then ASSERT().
230 @param Port The I/O port to read.
232 @return The value read.
244 __asm__
__volatile__ ("inb %w1,%b0" : "=a" (Data
) : "d" ((UINT16
)Port
));
249 Writes an 8-bit I/O port.
251 Writes the 8-bit I/O port specified by Port with the value specified by Value
252 and returns Value. This function must guarantee that all I/O read and write
253 operations are serialized.
255 If 8-bit I/O port operations are not supported, then ASSERT().
257 @param Port The I/O port to write.
258 @param Value The value to write to the I/O port.
260 @return The value written the I/O port.
271 __asm__
__volatile__ ("outb %b0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
276 Reads a 16-bit I/O port.
278 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
279 This function must guarantee that all I/O read and write operations are
282 If 16-bit I/O port operations are not supported, then ASSERT().
284 @param Port The I/O port to read.
286 @return The value read.
298 ASSERT ((Port
& 1) == 0);
299 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
304 Writes a 16-bit I/O port.
306 Writes the 16-bit I/O port specified by Port with the value specified by Value
307 and returns Value. This function must guarantee that all I/O read and write
308 operations are serialized.
310 If 16-bit I/O port operations are not supported, then ASSERT().
312 @param Port The I/O port to write.
313 @param Value The value to write to the I/O port.
315 @return The value written the I/O port.
326 ASSERT ((Port
& 1) == 0);
327 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
332 Reads a 32-bit I/O port.
334 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
335 This function must guarantee that all I/O read and write operations are
338 If 32-bit I/O port operations are not supported, then ASSERT().
340 @param Port The I/O port to read.
342 @return The value read.
354 ASSERT ((Port
& 3) == 0);
355 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
360 Writes a 32-bit I/O port.
362 Writes the 32-bit I/O port specified by Port with the value specified by Value
363 and returns Value. This function must guarantee that all I/O read and write
364 operations are serialized.
366 If 32-bit I/O port operations are not supported, then ASSERT().
368 @param Port The I/O port to write.
369 @param Value The value to write to the I/O port.
371 @return The value written the I/O port.
382 ASSERT ((Port
& 3) == 0);
383 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));