]>
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.
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.
72 return *(volatile UINT8
*)Address
= Value
;
76 Reads a 16-bit MMIO register.
78 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
79 returned. This function must guarantee that all MMIO read and write
80 operations are serialized.
82 If 16-bit MMIO register operations are not supported, then ASSERT().
83 If Address is not aligned on a 16-bit boundary, then ASSERT().
85 @param Address The MMIO register to read.
87 @return The value read.
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().
108 If Address is not aligned on a 16-bit boundary, then ASSERT().
110 @param Address The MMIO register to write.
111 @param Value The value to write to the MMIO register.
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().
135 If Address is not aligned on a 32-bit boundary, then ASSERT().
137 @param Address The MMIO register to read.
139 @return The value read.
148 ASSERT ((Address
& 3) == 0);
149 return *(volatile UINT32
*)Address
;
153 Writes a 32-bit MMIO register.
155 Writes the 32-bit MMIO register specified by Address with the value specified
156 by Value and returns Value. This function must guarantee that all MMIO read
157 and write operations are serialized.
159 If 32-bit MMIO register operations are not supported, then ASSERT().
160 If Address is not aligned on a 32-bit boundary, then ASSERT().
162 @param Address The MMIO register to write.
163 @param Value The value to write to the MMIO register.
175 ASSERT ((Address
& 3) == 0);
176 return *(volatile UINT32
*)Address
= Value
;
180 Reads a 64-bit MMIO register.
182 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
183 returned. This function must guarantee that all MMIO read and write
184 operations are serialized.
186 If 64-bit MMIO register operations are not supported, then ASSERT().
187 If Address is not aligned on a 64-bit boundary, then ASSERT().
189 @param Address The MMIO register to read.
191 @return The value read.
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().
212 If Address is not aligned on a 64-bit boundary, then ASSERT().
214 @param Address The MMIO register to write.
215 @param Value The value to write to the MMIO register.
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.
247 Reads an 8-bit I/O port.
249 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
250 This function must guarantee that all I/O read and write operations are
253 If 8-bit I/O port operations are not supported, then ASSERT().
255 @param Port The I/O port to read.
257 @return The value read.
268 __asm__
__volatile__ ("inb %w1,%b0" : "=a" (Data
) : "d" ((UINT16
)Port
));
273 Writes an 8-bit I/O port.
275 Writes the 8-bit I/O port specified by Port with the value specified by Value
276 and returns Value. This function must guarantee that all I/O read and write
277 operations are serialized.
279 If 8-bit I/O port operations are not supported, then ASSERT().
281 @param Port The I/O port to write.
282 @param Value The value to write to the I/O port.
284 @return The value written to the I/O port. It equals to the
285 input Value instead of the actual value read back from
291 Writes an 8-bit I/O port.
293 Writes the 8-bit I/O port specified by Port with the value specified by Value
294 and returns Value. This function must guarantee that all I/O read and write
295 operations are serialized.
297 If 8-bit I/O port operations are not supported, then ASSERT().
299 @param Port The I/O port to write.
300 @param Value The value to write to the I/O port.
302 @return The value written the I/O port.
312 __asm__
__volatile__ ("outb %b0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
317 Reads a 16-bit I/O port.
319 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
320 This function must guarantee that all I/O read and write operations are
323 If 16-bit I/O port operations are not supported, then ASSERT().
325 @param Port The I/O port to read.
327 @return The value read from Port.
332 Reads a 16-bit I/O port.
334 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
335 This function must guarantee that all I/O read and write operations are
338 If 16-bit I/O port operations are not supported, then ASSERT().
339 If Port is not aligned on a 16-bit boundary, then ASSERT().
341 @param Port The I/O port to read.
343 @return The value read.
354 ASSERT ((Port
& 1) == 0);
355 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
360 Writes a 16-bit I/O port.
362 Writes the 16-bit I/O port specified by Port with the value specified by Value
363 and returns Value. This function must guarantee that all I/O read and write
364 operations are serialized.
366 If 16-bit I/O port operations are not supported, then ASSERT().
368 @param Port The I/O port to write.
369 @param Value The value to write to the I/O port.
371 @return The value written to the I/O port. It equals to the
372 input Value instead of the actual value read back from
378 Writes a 16-bit I/O port.
380 Writes the 16-bit I/O port specified by Port with the value specified by Value
381 and returns Value. This function must guarantee that all I/O read and write
382 operations are serialized.
384 If 16-bit I/O port operations are not supported, then ASSERT().
385 If Port is not aligned on a 16-bit boundary, then ASSERT().
387 @param Port The I/O port to write.
388 @param Value The value to write to the I/O port.
390 @return The value written the I/O port.
400 ASSERT ((Port
& 1) == 0);
401 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
406 Reads a 32-bit I/O port.
408 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
409 This function must guarantee that all I/O read and write operations are
412 If 32-bit I/O port operations are not supported, then ASSERT().
414 @param Port The I/O port to read.
416 @return The value read from Port.
421 Reads a 32-bit I/O port.
423 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
424 This function must guarantee that all I/O read and write operations are
427 If 32-bit I/O port operations are not supported, then ASSERT().
428 If Port is not aligned on a 32-bit boundary, then ASSERT().
430 @param Port The I/O port to read.
432 @return The value read.
443 ASSERT ((Port
& 3) == 0);
444 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
449 Writes a 32-bit I/O port.
451 Writes the 32-bit I/O port specified by Port with the value specified by Value
452 and returns Value. This function must guarantee that all I/O read and write
453 operations are serialized.
455 If 32-bit I/O port operations are not supported, then ASSERT().
457 @param Port The I/O port to write.
458 @param Value The value to write to the I/O port.
460 @return The value written to the I/O port. It equals to the
461 input Value instead of the actual value read back from
467 Writes a 32-bit I/O port.
469 Writes the 32-bit I/O port specified by Port with the value specified by Value
470 and returns Value. This function must guarantee that all I/O read and write
471 operations are serialized.
473 If 32-bit I/O port operations are not supported, then ASSERT().
474 If Port is not aligned on a 32-bit boundary, then ASSERT().
476 @param Port The I/O port to write.
477 @param Value The value to write to the I/O port.
479 @return The value written the I/O port.
489 ASSERT ((Port
& 3) == 0);
490 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));