]>
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 "BaseIoLibIntrinsicInternal.h"
28 Reads an 8-bit MMIO register.
30 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
31 returned. This function must guarantee that all MMIO read and write
32 operations are serialized.
34 If 8-bit MMIO register operations are not supported, then ASSERT().
36 @param Address The MMIO register to read.
38 @return The value read from Address.
47 return *(volatile UINT8
*)Address
;
51 Writes an 8-bit MMIO register.
53 Writes the 8-bit MMIO register specified by Address with the value specified
54 by Value and returns Value. This function must guarantee that all MMIO read
55 and write operations are serialized.
57 If 8-bit MMIO register operations are not supported, then ASSERT().
59 @param Address The MMIO register to write.
60 @param Value The value to write to the MMIO register.
62 @return The value written to the Mmio. It equals to the input
63 Value instead of the actual value read back from the
73 return *(volatile UINT8
*)Address
= Value
;
77 Reads a 16-bit MMIO register.
79 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
80 returned. This function must guarantee that all MMIO read and write
81 operations are serialized.
83 If 16-bit MMIO register operations are not supported, then ASSERT().
85 @param Address The MMIO register to read.
87 @return The value read from Address.
96 ASSERT ((Address
& 1) == 0);
97 return *(volatile UINT16
*)Address
;
101 Writes a 16-bit MMIO register.
103 Writes the 16-bit MMIO register specified by Address with the value specified
104 by Value and returns Value. This function must guarantee that all MMIO read
105 and write operations are serialized.
107 If 16-bit MMIO register operations are not supported, then ASSERT().
109 @param Address The MMIO register to write.
110 @param Value The value to write to the MMIO register.
112 @return The value written to the Mmio. It equals to the input
113 Value instead of the actual value read back from the
123 ASSERT ((Address
& 1) == 0);
124 return *(volatile UINT16
*)Address
= Value
;
128 Reads a 32-bit MMIO register.
130 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
131 returned. This function must guarantee that all MMIO read and write
132 operations are serialized.
134 If 32-bit MMIO register operations are not supported, then ASSERT().
136 @param Address The MMIO register to read.
138 @return The value read from Address.
147 ASSERT ((Address
& 3) == 0);
148 return *(volatile UINT32
*)Address
;
152 Writes a 32-bit MMIO register.
154 Writes the 32-bit MMIO register specified by Address with the value specified
155 by Value and returns Value. This function must guarantee that all MMIO read
156 and write operations are serialized.
158 If 32-bit MMIO register operations are not supported, then ASSERT().
160 @param Address The MMIO register to write.
161 @param Value The value to write to the MMIO register.
163 @return The value written to the Mmio. It equals to the input
164 Value instead of the actual value read back from the
174 ASSERT ((Address
& 3) == 0);
175 return *(volatile UINT32
*)Address
= Value
;
179 Reads a 64-bit MMIO register.
181 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
182 returned. This function must guarantee that all MMIO read and write
183 operations are serialized.
185 If 64-bit MMIO register operations are not supported, then ASSERT().
187 @param Address The MMIO register to read.
189 @return The value read from Address.
198 ASSERT ((Address
& 7) == 0);
199 return *(volatile UINT64
*)Address
;
203 Writes a 64-bit MMIO register.
205 Writes the 64-bit MMIO register specified by Address with the value specified
206 by Value and returns Value. This function must guarantee that all MMIO read
207 and write operations are serialized.
209 If 64-bit MMIO register operations are not supported, then ASSERT().
211 @param Address The MMIO register to write.
212 @param Value The value to write to the MMIO register.
214 @return The value written to the Mmio. It equals to the input
215 Value instead of the actual value read back from the
225 ASSERT ((Address
& 7) == 0);
226 return *(volatile UINT64
*)Address
= Value
;
232 Reads an 8-bit I/O port.
234 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
235 This function must guarantee that all I/O read and write operations are
238 If 8-bit I/O port operations are not supported, then ASSERT().
240 @param Port The I/O port to read.
242 @return The value read from Port.
254 __asm__
__volatile__ ("inb %w1,%b0" : "=a" (Data
) : "d" ((UINT16
)Port
));
259 Writes an 8-bit I/O port.
261 Writes the 8-bit I/O port specified by Port with the value specified by Value
262 and returns Value. This function must guarantee that all I/O read and write
263 operations are serialized.
265 If 8-bit I/O port operations are not supported, then ASSERT().
267 @param Port The I/O port to write.
268 @param Value The value to write to the I/O port.
270 @return The value written to the I/O port. It equals to the
271 input Value instead of the actual value read back from
283 __asm__
__volatile__ ("outb %b0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
288 Reads a 16-bit I/O port.
290 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
291 This function must guarantee that all I/O read and write operations are
294 If 16-bit I/O port operations are not supported, then ASSERT().
296 @param Port The I/O port to read.
298 @return The value read from Port.
310 ASSERT ((Port
& 1) == 0);
311 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
316 Writes a 16-bit I/O port.
318 Writes the 16-bit I/O port specified by Port with the value specified by Value
319 and returns Value. This function must guarantee that all I/O read and write
320 operations are serialized.
322 If 16-bit I/O port operations are not supported, then ASSERT().
324 @param Port The I/O port to write.
325 @param Value The value to write to the I/O port.
327 @return The value written to the I/O port. It equals to the
328 input Value instead of the actual value read back from
340 ASSERT ((Port
& 1) == 0);
341 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
346 Reads a 32-bit I/O port.
348 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
349 This function must guarantee that all I/O read and write operations are
352 If 32-bit I/O port operations are not supported, then ASSERT().
354 @param Port The I/O port to read.
356 @return The value read from Port.
368 ASSERT ((Port
& 3) == 0);
369 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
374 Writes a 32-bit I/O port.
376 Writes the 32-bit I/O port specified by Port with the value specified by Value
377 and returns Value. This function must guarantee that all I/O read and write
378 operations are serialized.
380 If 32-bit I/O port operations are not supported, then ASSERT().
382 @param Port The I/O port to write.
383 @param Value The value to write to the I/O port.
385 @return The value written to the I/O port. It equals to the
386 input Value instead of the actual value read back from
398 ASSERT ((Port
& 3) == 0);
399 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));