]>
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 - 2021, Intel Corporation. All rights reserved.<BR>
14 SPDX-License-Identifier: BSD-2-Clause-Patent
19 #include "BaseIoLibIntrinsicInternal.h"
22 Reads an 8-bit I/O port.
24 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
25 This function must guarantee that all I/O read and write operations are
28 If 8-bit I/O port operations are not supported, then ASSERT().
30 @param Port The I/O port to read.
32 @return The value read.
44 Flag
= FilterBeforeIoRead (FilterWidth8
, Port
, &Data
);
46 __asm__
__volatile__ ("inb %w1,%b0" : "=a" (Data
) : "d" ((UINT16
)Port
));
48 FilterAfterIoRead (FilterWidth8
, Port
, &Data
);
54 Writes an 8-bit I/O port.
56 Writes the 8-bit I/O port specified by Port with the value specified by Value
57 and returns Value. This function must guarantee that all I/O read and write
58 operations are serialized.
60 If 8-bit I/O port operations are not supported, then ASSERT().
62 @param Port The I/O port to write.
63 @param Value The value to write to the I/O port.
65 @return The value written the I/O port.
77 Flag
= FilterBeforeIoWrite (FilterWidth8
, Port
, &Value
);
79 __asm__
__volatile__ ("outb %b0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
81 FilterAfterIoWrite (FilterWidth8
, Port
, &Value
);
87 Reads a 16-bit I/O port.
89 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
90 This function must guarantee that all I/O read and write operations are
93 If 16-bit I/O port operations are not supported, then ASSERT().
94 If Port is not aligned on a 16-bit boundary, then ASSERT().
96 @param Port The I/O port to read.
98 @return The value read.
110 ASSERT ((Port
& 1) == 0);
112 Flag
= FilterBeforeIoRead (FilterWidth16
, Port
, &Data
);
114 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
116 FilterAfterIoRead (FilterWidth16
, Port
, &Data
);
122 Writes a 16-bit I/O port.
124 Writes the 16-bit I/O port specified by Port with the value specified by Value
125 and returns Value. This function must guarantee that all I/O read and write
126 operations are serialized.
128 If 16-bit I/O port operations are not supported, then ASSERT().
129 If Port is not aligned on a 16-bit boundary, then ASSERT().
131 @param Port The I/O port to write.
132 @param Value The value to write to the I/O port.
134 @return The value written the I/O port.
147 ASSERT ((Port
& 1) == 0);
149 Flag
= FilterBeforeIoWrite (FilterWidth16
, Port
, &Value
);
151 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
153 FilterAfterIoWrite (FilterWidth16
, Port
, &Value
);
159 Reads a 32-bit I/O port.
161 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
162 This function must guarantee that all I/O read and write operations are
165 If 32-bit I/O port operations are not supported, then ASSERT().
166 If Port is not aligned on a 32-bit boundary, then ASSERT().
168 @param Port The I/O port to read.
170 @return The value read.
182 ASSERT ((Port
& 3) == 0);
184 Flag
= FilterBeforeIoRead (FilterWidth32
, Port
, &Data
);
186 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
188 FilterAfterIoRead (FilterWidth32
, Port
, &Data
);
194 Writes a 32-bit I/O port.
196 Writes the 32-bit I/O port specified by Port with the value specified by Value
197 and returns Value. This function must guarantee that all I/O read and write
198 operations are serialized.
200 If 32-bit I/O port operations are not supported, then ASSERT().
201 If Port is not aligned on a 32-bit boundary, then ASSERT().
203 @param Port The I/O port to write.
204 @param Value The value to write to the I/O port.
206 @return The value written the I/O port.
218 ASSERT ((Port
& 3) == 0);
220 Flag
= FilterBeforeIoWrite (FilterWidth32
, Port
, &Value
);
222 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
224 FilterAfterIoWrite (FilterWidth32
, Port
, &Value
);