]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseIoLibIntrinsic/IoLibGcc.c
36a76a691f1a820f5adc097389136694d2c881c3
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.
23 #include "BaseIoLibIntrinsicInternal.h"
26 Reads an 8-bit MMIO register.
28 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
29 returned. This function must guarantee that all MMIO read and write
30 operations are serialized.
32 If 8-bit MMIO register operations are not supported, then ASSERT().
34 @param Address The MMIO register to read.
36 @return The value read.
45 return *(volatile UINT8
*)Address
;
49 Writes an 8-bit MMIO register.
51 Writes the 8-bit MMIO register specified by Address with the value specified
52 by Value and returns Value. This function must guarantee that all MMIO read
53 and write operations are serialized.
55 If 8-bit MMIO register operations are not supported, then ASSERT().
57 @param Address The MMIO register to write.
58 @param Value The value to write to the MMIO register.
68 return *(volatile UINT8
*)Address
= Value
;
72 Reads a 16-bit MMIO register.
74 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
75 returned. This function must guarantee that all MMIO read and write
76 operations are serialized.
78 If 16-bit MMIO register operations are not supported, then ASSERT().
80 @param Address The MMIO register to read.
82 @return The value read.
91 ASSERT ((Address
& 1) == 0);
92 return *(volatile UINT16
*)Address
;
96 Writes a 16-bit MMIO register.
98 Writes the 16-bit MMIO register specified by Address with the value specified
99 by Value and returns Value. This function must guarantee that all MMIO read
100 and write operations are serialized.
102 If 16-bit MMIO register operations are not supported, then ASSERT().
104 @param Address The MMIO register to write.
105 @param Value The value to write to the MMIO register.
115 ASSERT ((Address
& 1) == 0);
116 return *(volatile UINT16
*)Address
= Value
;
120 Reads a 32-bit MMIO register.
122 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
123 returned. This function must guarantee that all MMIO read and write
124 operations are serialized.
126 If 32-bit MMIO register operations are not supported, then ASSERT().
128 @param Address The MMIO register to read.
130 @return The value read.
139 ASSERT ((Address
& 3) == 0);
140 return *(volatile UINT32
*)Address
;
144 Writes a 32-bit MMIO register.
146 Writes the 32-bit MMIO register specified by Address with the value specified
147 by Value and returns Value. This function must guarantee that all MMIO read
148 and write operations are serialized.
150 If 32-bit MMIO register operations are not supported, then ASSERT().
152 @param Address The MMIO register to write.
153 @param Value The value to write to the MMIO register.
163 ASSERT ((Address
& 3) == 0);
164 return *(volatile UINT32
*)Address
= Value
;
168 Reads a 64-bit MMIO register.
170 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
171 returned. This function must guarantee that all MMIO read and write
172 operations are serialized.
174 If 64-bit MMIO register operations are not supported, then ASSERT().
176 @param Address The MMIO register to read.
178 @return The value read.
187 ASSERT ((Address
& 7) == 0);
188 return *(volatile UINT64
*)Address
;
192 Writes a 64-bit MMIO register.
194 Writes the 64-bit MMIO register specified by Address with the value specified
195 by Value and returns Value. This function must guarantee that all MMIO read
196 and write operations are serialized.
198 If 64-bit MMIO register operations are not supported, then ASSERT().
200 @param Address The MMIO register to write.
201 @param Value The value to write to the MMIO register.
211 ASSERT ((Address
& 7) == 0);
212 return *(volatile UINT64
*)Address
= Value
;
218 Reads an 8-bit I/O port.
220 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
221 This function must guarantee that all I/O read and write operations are
224 If 8-bit I/O port operations are not supported, then ASSERT().
226 @param Port The I/O port to read.
228 @return The value read.
240 __asm__
__volatile__ ("inb %w1,%b0" : "=a" (Data
) : "d" ((UINT16
)Port
));
245 Writes an 8-bit I/O port.
247 Writes the 8-bit I/O port specified by Port with the value specified by Value
248 and returns Value. This function must guarantee that all I/O read and write
249 operations are serialized.
251 If 8-bit I/O port operations are not supported, then ASSERT().
253 @param Port The I/O port to write.
254 @param Value The value to write to the I/O port.
256 @return The value written the I/O port.
267 __asm__
__volatile__ ("outb %b0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
272 Reads a 16-bit I/O port.
274 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
275 This function must guarantee that all I/O read and write operations are
278 If 16-bit I/O port operations are not supported, then ASSERT().
280 @param Port The I/O port to read.
282 @return The value read.
294 ASSERT ((Port
& 1) == 0);
295 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
300 Writes a 16-bit I/O port.
302 Writes the 16-bit I/O port specified by Port with the value specified by Value
303 and returns Value. This function must guarantee that all I/O read and write
304 operations are serialized.
306 If 16-bit I/O port operations are not supported, then ASSERT().
308 @param Port The I/O port to write.
309 @param Value The value to write to the I/O port.
311 @return The value written the I/O port.
322 ASSERT ((Port
& 1) == 0);
323 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
328 Reads a 32-bit I/O port.
330 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
331 This function must guarantee that all I/O read and write operations are
334 If 32-bit I/O port operations are not supported, then ASSERT().
336 @param Port The I/O port to read.
338 @return The value read.
350 ASSERT ((Port
& 3) == 0);
351 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
356 Writes a 32-bit I/O port.
358 Writes the 32-bit I/O port specified by Port with the value specified by Value
359 and returns Value. This function must guarantee that all I/O read and write
360 operations are serialized.
362 If 32-bit I/O port operations are not supported, then ASSERT().
364 @param Port The I/O port to write.
365 @param Value The value to write to the I/O port.
367 @return The value written the I/O port.
378 ASSERT ((Port
& 3) == 0);
379 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));