]>
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 common header file for this module.
27 #include "BaseIoLibIntrinsicInternal.h"
30 Reads an 8-bit MMIO register.
32 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
33 returned. This function must guarantee that all MMIO read and write
34 operations are serialized.
36 If 8-bit MMIO register operations are not supported, then ASSERT().
38 @param Address The MMIO register to read.
40 @return The value read from Address.
49 return *(volatile UINT8
*)Address
;
53 Writes an 8-bit MMIO register.
55 Writes the 8-bit MMIO register specified by Address with the value specified
56 by Value and returns Value. This function must guarantee that all MMIO read
57 and write operations are serialized.
59 If 8-bit MMIO register operations are not supported, then ASSERT().
61 @param Address The MMIO register to write.
62 @param Value The value to write to the MMIO register.
64 @return The value written to the Mmio. It equals to the input
65 Value instead of the actual value read back from the
75 return *(volatile UINT8
*)Address
= Value
;
79 Reads a 16-bit MMIO register.
81 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
82 returned. This function must guarantee that all MMIO read and write
83 operations are serialized.
85 If 16-bit MMIO register operations are not supported, then ASSERT().
87 @param Address The MMIO register to read.
89 @return The value read from Address.
98 ASSERT ((Address
& 1) == 0);
99 return *(volatile UINT16
*)Address
;
103 Writes a 16-bit MMIO register.
105 Writes the 16-bit MMIO register specified by Address with the value specified
106 by Value and returns Value. This function must guarantee that all MMIO read
107 and write operations are serialized.
109 If 16-bit MMIO register operations are not supported, then ASSERT().
111 @param Address The MMIO register to write.
112 @param Value The value to write to the MMIO register.
114 @return The value written to the Mmio. It equals to the input
115 Value instead of the actual value read back from the
125 ASSERT ((Address
& 1) == 0);
126 return *(volatile UINT16
*)Address
= Value
;
130 Reads a 32-bit MMIO register.
132 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
133 returned. This function must guarantee that all MMIO read and write
134 operations are serialized.
136 If 32-bit MMIO register operations are not supported, then ASSERT().
138 @param Address The MMIO register to read.
140 @return The value read from Address.
149 ASSERT ((Address
& 3) == 0);
150 return *(volatile UINT32
*)Address
;
154 Writes a 32-bit MMIO register.
156 Writes the 32-bit MMIO register specified by Address with the value specified
157 by Value and returns Value. This function must guarantee that all MMIO read
158 and write operations are serialized.
160 If 32-bit MMIO register operations are not supported, then ASSERT().
162 @param Address The MMIO register to write.
163 @param Value The value to write to the MMIO register.
165 @return The value written to the Mmio. It equals to the input
166 Value instead of the actual value read back from the
176 ASSERT ((Address
& 3) == 0);
177 return *(volatile UINT32
*)Address
= Value
;
181 Reads a 64-bit MMIO register.
183 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
184 returned. This function must guarantee that all MMIO read and write
185 operations are serialized.
187 If 64-bit MMIO register operations are not supported, then ASSERT().
189 @param Address The MMIO register to read.
191 @return The value read from Address.
200 ASSERT ((Address
& 7) == 0);
201 return *(volatile UINT64
*)Address
;
205 Writes a 64-bit MMIO register.
207 Writes the 64-bit MMIO register specified by Address with the value specified
208 by Value and returns Value. This function must guarantee that all MMIO read
209 and write operations are serialized.
211 If 64-bit MMIO register operations are not supported, then ASSERT().
213 @param Address The MMIO register to write.
214 @param Value The value to write to the MMIO register.
216 @return The value written to the Mmio. It equals to the input
217 Value instead of the actual value read back from the
227 ASSERT ((Address
& 7) == 0);
228 return *(volatile UINT64
*)Address
= Value
;
234 Reads an 8-bit I/O port.
236 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
237 This function must guarantee that all I/O read and write operations are
240 If 8-bit I/O port operations are not supported, then ASSERT().
242 @param Port The I/O port to read.
244 @return The value read from Port.
256 __asm__
__volatile__ ("inb %w1,%b0" : "=a" (Data
) : "d" ((UINT16
)Port
));
261 Writes an 8-bit I/O port.
263 Writes the 8-bit I/O port specified by Port with the value specified by Value
264 and returns Value. This function must guarantee that all I/O read and write
265 operations are serialized.
267 If 8-bit I/O port operations are not supported, then ASSERT().
269 @param Port The I/O port to write.
270 @param Value The value to write to the I/O port.
272 @return The value written to the I/O port. It equals to the
273 input Value instead of the actual value read back from
285 __asm__
__volatile__ ("outb %b0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
290 Reads a 16-bit I/O port.
292 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
293 This function must guarantee that all I/O read and write operations are
296 If 16-bit I/O port operations are not supported, then ASSERT().
298 @param Port The I/O port to read.
300 @return The value read from Port.
312 ASSERT ((Port
& 1) == 0);
313 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
318 Writes a 16-bit I/O port.
320 Writes the 16-bit I/O port specified by Port with the value specified by Value
321 and returns Value. This function must guarantee that all I/O read and write
322 operations are serialized.
324 If 16-bit I/O port operations are not supported, then ASSERT().
326 @param Port The I/O port to write.
327 @param Value The value to write to the I/O port.
329 @return The value written to the I/O port. It equals to the
330 input Value instead of the actual value read back from
342 ASSERT ((Port
& 1) == 0);
343 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
348 Reads a 32-bit I/O port.
350 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
351 This function must guarantee that all I/O read and write operations are
354 If 32-bit I/O port operations are not supported, then ASSERT().
356 @param Port The I/O port to read.
358 @return The value read from Port.
370 ASSERT ((Port
& 3) == 0);
371 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
376 Writes a 32-bit I/O port.
378 Writes the 32-bit I/O port specified by Port with the value specified by Value
379 and returns Value. This function must guarantee that all I/O read and write
380 operations are serialized.
382 If 32-bit I/O port operations are not supported, then ASSERT().
384 @param Port The I/O port to write.
385 @param Value The value to write to the I/O port.
387 @return The value written to the I/O port. It equals to the
388 input Value instead of the actual value read back from
400 ASSERT ((Port
& 3) == 0);
401 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));