]>
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.
22 Module Name: IoLibGcc.c
27 // Include common header file for this module.
29 #include "CommonHeader.h"
32 Reads an 8-bit MMIO register.
34 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
35 returned. This function must guarantee that all MMIO read and write
36 operations are serialized.
38 If 8-bit MMIO register operations are not supported, then ASSERT().
40 @param Address The MMIO register to read.
42 @return The value read.
51 return *(volatile UINT8
*)Address
;
55 Writes an 8-bit MMIO register.
57 Writes the 8-bit MMIO register specified by Address with the value specified
58 by Value and returns Value. This function must guarantee that all MMIO read
59 and write operations are serialized.
61 If 8-bit MMIO register operations are not supported, then ASSERT().
63 @param Address The MMIO register to write.
64 @param Value The value to write to the MMIO register.
74 return *(volatile UINT8
*)Address
= Value
;
78 Reads a 16-bit MMIO register.
80 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
81 returned. This function must guarantee that all MMIO read and write
82 operations are serialized.
84 If 16-bit MMIO register operations are not supported, then ASSERT().
86 @param Address The MMIO register to read.
88 @return The value read.
97 ASSERT ((Address
& 1) == 0);
98 return *(volatile UINT16
*)Address
;
102 Writes a 16-bit MMIO register.
104 Writes the 16-bit MMIO register specified by Address with the value specified
105 by Value and returns Value. This function must guarantee that all MMIO read
106 and write operations are serialized.
108 If 16-bit MMIO register operations are not supported, then ASSERT().
110 @param Address The MMIO register to write.
111 @param Value The value to write to the MMIO register.
121 ASSERT ((Address
& 1) == 0);
122 return *(volatile UINT16
*)Address
= Value
;
126 Reads a 32-bit MMIO register.
128 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
129 returned. This function must guarantee that all MMIO read and write
130 operations are serialized.
132 If 32-bit MMIO register operations are not supported, then ASSERT().
134 @param Address The MMIO register to read.
136 @return The value read.
145 ASSERT ((Address
& 3) == 0);
146 return *(volatile UINT32
*)Address
;
150 Writes a 32-bit MMIO register.
152 Writes the 32-bit MMIO register specified by Address with the value specified
153 by Value and returns Value. This function must guarantee that all MMIO read
154 and write operations are serialized.
156 If 32-bit MMIO register operations are not supported, then ASSERT().
158 @param Address The MMIO register to write.
159 @param Value The value to write to the MMIO register.
169 ASSERT ((Address
& 3) == 0);
170 return *(volatile UINT32
*)Address
= Value
;
174 Reads a 64-bit MMIO register.
176 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
177 returned. This function must guarantee that all MMIO read and write
178 operations are serialized.
180 If 64-bit MMIO register operations are not supported, then ASSERT().
182 @param Address The MMIO register to read.
184 @return The value read.
193 ASSERT ((Address
& 7) == 0);
194 return *(volatile UINT64
*)Address
;
198 Writes a 64-bit MMIO register.
200 Writes the 64-bit MMIO register specified by Address with the value specified
201 by Value and returns Value. This function must guarantee that all MMIO read
202 and write operations are serialized.
204 If 64-bit MMIO register operations are not supported, then ASSERT().
206 @param Address The MMIO register to write.
207 @param Value The value to write to the MMIO register.
217 ASSERT ((Address
& 7) == 0);
218 return *(volatile UINT64
*)Address
= Value
;
224 Reads an 8-bit I/O port.
226 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
227 This function must guarantee that all I/O read and write operations are
230 If 8-bit I/O port operations are not supported, then ASSERT().
232 @param Port The I/O port to read.
234 @return The value read.
246 __asm__
__volatile__ ("inb %w1,%b0" : "=a" (Data
) : "d" ((UINT16
)Port
));
251 Writes an 8-bit I/O port.
253 Writes the 8-bit I/O port specified by Port with the value specified by Value
254 and returns Value. This function must guarantee that all I/O read and write
255 operations are serialized.
257 If 8-bit I/O port operations are not supported, then ASSERT().
259 @param Port The I/O port to write.
260 @param Value The value to write to the I/O port.
262 @return The value written the I/O port.
273 __asm__
__volatile__ ("outb %b0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
278 Reads a 16-bit I/O port.
280 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
281 This function must guarantee that all I/O read and write operations are
284 If 16-bit I/O port operations are not supported, then ASSERT().
286 @param Port The I/O port to read.
288 @return The value read.
300 ASSERT ((Port
& 1) == 0);
301 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
306 Writes a 16-bit I/O port.
308 Writes the 16-bit I/O port specified by Port with the value specified by Value
309 and returns Value. This function must guarantee that all I/O read and write
310 operations are serialized.
312 If 16-bit I/O port operations are not supported, then ASSERT().
314 @param Port The I/O port to write.
315 @param Value The value to write to the I/O port.
317 @return The value written the I/O port.
328 ASSERT ((Port
& 1) == 0);
329 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
334 Reads a 32-bit I/O port.
336 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
337 This function must guarantee that all I/O read and write operations are
340 If 32-bit I/O port operations are not supported, then ASSERT().
342 @param Port The I/O port to read.
344 @return The value read.
356 ASSERT ((Port
& 3) == 0);
357 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
362 Writes a 32-bit I/O port.
364 Writes the 32-bit I/O port specified by Port with the value specified by Value
365 and returns Value. This function must guarantee that all I/O read and write
366 operations are serialized.
368 If 32-bit I/O port operations are not supported, then ASSERT().
370 @param Port The I/O port to write.
371 @param Value The value to write to the I/O port.
373 @return The value written the I/O port.
384 ASSERT ((Port
& 3) == 0);
385 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));