]>
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, 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
29 Reads an 8-bit MMIO register.
31 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
32 returned. This function must guarantee that all MMIO read and write
33 operations are serialized.
35 If 8-bit MMIO register operations are not supported, then ASSERT().
37 @param Address The MMIO register to read.
39 @return The value read.
48 return *(volatile UINT8
*)Address
;
52 Writes an 8-bit MMIO register.
54 Writes the 8-bit MMIO register specified by Address with the value specified
55 by Value and returns Value. This function must guarantee that all MMIO read
56 and write operations are serialized.
58 If 8-bit MMIO register operations are not supported, then ASSERT().
60 @param Address The MMIO register to write.
61 @param Value The value to write to the MMIO register.
71 return *(volatile UINT8
*)Address
= Value
;
75 Reads a 16-bit MMIO register.
77 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
78 returned. This function must guarantee that all MMIO read and write
79 operations are serialized.
81 If 16-bit MMIO register operations are not supported, then ASSERT().
83 @param Address The MMIO register to read.
85 @return The value read.
94 ASSERT ((Address
& 1) == 0);
95 return *(volatile UINT16
*)Address
;
99 Writes a 16-bit MMIO register.
101 Writes the 16-bit MMIO register specified by Address with the value specified
102 by Value and returns Value. This function must guarantee that all MMIO read
103 and write operations are serialized.
105 If 16-bit MMIO register operations are not supported, then ASSERT().
107 @param Address The MMIO register to write.
108 @param Value The value to write to the MMIO register.
118 ASSERT ((Address
& 1) == 0);
119 return *(volatile UINT16
*)Address
= Value
;
123 Reads a 32-bit MMIO register.
125 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
126 returned. This function must guarantee that all MMIO read and write
127 operations are serialized.
129 If 32-bit MMIO register operations are not supported, then ASSERT().
131 @param Address The MMIO register to read.
133 @return The value read.
142 ASSERT ((Address
& 3) == 0);
143 return *(volatile UINT32
*)Address
;
147 Writes a 32-bit MMIO register.
149 Writes the 32-bit MMIO register specified by Address with the value specified
150 by Value and returns Value. This function must guarantee that all MMIO read
151 and write operations are serialized.
153 If 32-bit MMIO register operations are not supported, then ASSERT().
155 @param Address The MMIO register to write.
156 @param Value The value to write to the MMIO register.
166 ASSERT ((Address
& 3) == 0);
167 return *(volatile UINT32
*)Address
= Value
;
171 Reads a 64-bit MMIO register.
173 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
174 returned. This function must guarantee that all MMIO read and write
175 operations are serialized.
177 If 64-bit MMIO register operations are not supported, then ASSERT().
179 @param Address The MMIO register to read.
181 @return The value read.
190 ASSERT ((Address
& 7) == 0);
191 return *(volatile UINT64
*)Address
;
195 Writes a 64-bit MMIO register.
197 Writes the 64-bit MMIO register specified by Address with the value specified
198 by Value and returns Value. This function must guarantee that all MMIO read
199 and write operations are serialized.
201 If 64-bit MMIO register operations are not supported, then ASSERT().
203 @param Address The MMIO register to write.
204 @param Value The value to write to the MMIO register.
214 ASSERT ((Address
& 7) == 0);
215 return *(volatile UINT64
*)Address
= Value
;
221 Reads an 8-bit I/O port.
223 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
224 This function must guarantee that all I/O read and write operations are
227 If 8-bit I/O port operations are not supported, then ASSERT().
229 @param Port The I/O port to read.
231 @return The value read.
243 __asm__
__volatile__ ("inb %w1,%b0" : "=a" (Data
) : "d" ((UINT16
)Port
));
248 Writes an 8-bit I/O port.
250 Writes the 8-bit I/O port specified by Port with the value specified by Value
251 and returns Value. This function must guarantee that all I/O read and write
252 operations are serialized.
254 If 8-bit I/O port operations are not supported, then ASSERT().
256 @param Port The I/O port to write.
257 @param Value The value to write to the I/O port.
259 @return The value written the I/O port.
270 __asm__
__volatile__ ("outb %b0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
275 Reads a 16-bit I/O port.
277 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
278 This function must guarantee that all I/O read and write operations are
281 If 16-bit I/O port operations are not supported, then ASSERT().
283 @param Port The I/O port to read.
285 @return The value read.
297 ASSERT ((Port
& 1) == 0);
298 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
303 Writes a 16-bit I/O port.
305 Writes the 16-bit I/O port specified by Port with the value specified by Value
306 and returns Value. This function must guarantee that all I/O read and write
307 operations are serialized.
309 If 16-bit I/O port operations are not supported, then ASSERT().
311 @param Port The I/O port to write.
312 @param Value The value to write to the I/O port.
314 @return The value written the I/O port.
325 ASSERT ((Port
& 1) == 0);
326 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
331 Reads a 32-bit I/O port.
333 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
334 This function must guarantee that all I/O read and write operations are
337 If 32-bit I/O port operations are not supported, then ASSERT().
339 @param Port The I/O port to read.
341 @return The value read.
353 ASSERT ((Port
& 3) == 0);
354 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
359 Writes a 32-bit I/O port.
361 Writes the 32-bit I/O port specified by Port with the value specified by Value
362 and returns Value. This function must guarantee that all I/O read and write
363 operations are serialized.
365 If 32-bit I/O port operations are not supported, then ASSERT().
367 @param Port The I/O port to write.
368 @param Value The value to write to the I/O port.
370 @return The value written the I/O port.
381 ASSERT ((Port
& 3) == 0);
382 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));