]>
git.proxmox.com Git - mirror_edk2.git/blob - OldMdePkg/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 Reads an 8-bit MMIO register.
29 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
30 returned. This function must guarantee that all MMIO read and write
31 operations are serialized.
33 If 8-bit MMIO register operations are not supported, then ASSERT().
35 @param Address The MMIO register to read.
37 @return The value read.
46 return *(volatile UINT8
*)Address
;
50 Writes an 8-bit MMIO register.
52 Writes the 8-bit MMIO register specified by Address with the value specified
53 by Value and returns Value. This function must guarantee that all MMIO read
54 and write operations are serialized.
56 If 8-bit MMIO register operations are not supported, then ASSERT().
58 @param Address The MMIO register to write.
59 @param Value The value to write to the MMIO register.
69 return *(volatile UINT8
*)Address
= Value
;
73 Reads a 16-bit MMIO register.
75 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
76 returned. This function must guarantee that all MMIO read and write
77 operations are serialized.
79 If 16-bit MMIO register operations are not supported, then ASSERT().
81 @param Address The MMIO register to read.
83 @return The value read.
92 ASSERT ((Address
& 1) == 0);
93 return *(volatile UINT16
*)Address
;
97 Writes a 16-bit MMIO register.
99 Writes the 16-bit MMIO register specified by Address with the value specified
100 by Value and returns Value. This function must guarantee that all MMIO read
101 and write operations are serialized.
103 If 16-bit MMIO register operations are not supported, then ASSERT().
105 @param Address The MMIO register to write.
106 @param Value The value to write to the MMIO register.
116 ASSERT ((Address
& 1) == 0);
117 return *(volatile UINT16
*)Address
= Value
;
121 Reads a 32-bit MMIO register.
123 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
124 returned. This function must guarantee that all MMIO read and write
125 operations are serialized.
127 If 32-bit MMIO register operations are not supported, then ASSERT().
129 @param Address The MMIO register to read.
131 @return The value read.
140 ASSERT ((Address
& 3) == 0);
141 return *(volatile UINT32
*)Address
;
145 Writes a 32-bit MMIO register.
147 Writes the 32-bit MMIO register specified by Address with the value specified
148 by Value and returns Value. This function must guarantee that all MMIO read
149 and write operations are serialized.
151 If 32-bit MMIO register operations are not supported, then ASSERT().
153 @param Address The MMIO register to write.
154 @param Value The value to write to the MMIO register.
164 ASSERT ((Address
& 3) == 0);
165 return *(volatile UINT32
*)Address
= Value
;
169 Reads a 64-bit MMIO register.
171 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
172 returned. This function must guarantee that all MMIO read and write
173 operations are serialized.
175 If 64-bit MMIO register operations are not supported, then ASSERT().
177 @param Address The MMIO register to read.
179 @return The value read.
188 ASSERT ((Address
& 7) == 0);
189 return *(volatile UINT64
*)Address
;
193 Writes a 64-bit MMIO register.
195 Writes the 64-bit MMIO register specified by Address with the value specified
196 by Value and returns Value. This function must guarantee that all MMIO read
197 and write operations are serialized.
199 If 64-bit MMIO register operations are not supported, then ASSERT().
201 @param Address The MMIO register to write.
202 @param Value The value to write to the MMIO register.
212 ASSERT ((Address
& 7) == 0);
213 return *(volatile UINT64
*)Address
= Value
;
219 Reads an 8-bit I/O port.
221 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
222 This function must guarantee that all I/O read and write operations are
225 If 8-bit I/O port operations are not supported, then ASSERT().
227 @param Port The I/O port to read.
229 @return The value read.
241 __asm__
__volatile__ ("inb %w1,%b0" : "=a" (Data
) : "d" ((UINT16
)Port
));
246 Writes an 8-bit I/O port.
248 Writes the 8-bit I/O port specified by Port with the value specified by Value
249 and returns Value. This function must guarantee that all I/O read and write
250 operations are serialized.
252 If 8-bit I/O port operations are not supported, then ASSERT().
254 @param Port The I/O port to write.
255 @param Value The value to write to the I/O port.
257 @return The value written the I/O port.
268 __asm__
__volatile__ ("outb %b0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
273 Reads a 16-bit I/O port.
275 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
276 This function must guarantee that all I/O read and write operations are
279 If 16-bit I/O port operations are not supported, then ASSERT().
281 @param Port The I/O port to read.
283 @return The value read.
295 ASSERT ((Port
& 1) == 0);
296 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
301 Writes a 16-bit I/O port.
303 Writes the 16-bit I/O port specified by Port with the value specified by Value
304 and returns Value. This function must guarantee that all I/O read and write
305 operations are serialized.
307 If 16-bit I/O port operations are not supported, then ASSERT().
309 @param Port The I/O port to write.
310 @param Value The value to write to the I/O port.
312 @return The value written the I/O port.
323 ASSERT ((Port
& 1) == 0);
324 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
329 Reads a 32-bit I/O port.
331 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
332 This function must guarantee that all I/O read and write operations are
335 If 32-bit I/O port operations are not supported, then ASSERT().
337 @param Port The I/O port to read.
339 @return The value read.
351 ASSERT ((Port
& 3) == 0);
352 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
357 Writes a 32-bit I/O port.
359 Writes the 32-bit I/O port specified by Port with the value specified by Value
360 and returns Value. This function must guarantee that all I/O read and write
361 operations are serialized.
363 If 32-bit I/O port operations are not supported, then ASSERT().
365 @param Port The I/O port to write.
366 @param Value The value to write to the I/O port.
368 @return The value written the I/O port.
379 ASSERT ((Port
& 3) == 0);
380 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));