]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibGcc.c
05a739085967c1390ea5ebb5f42ba5cac31acd06
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
18 #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 For Td guest TDVMCALL_IO is invoked to read I/O port.
32 @param Port The I/O port to read.
34 @return The value read.
46 Flag
= FilterBeforeIoRead (FilterWidth8
, Port
, &Data
);
49 Data
= TdIoRead8 (Port
);
51 __asm__
__volatile__ ("inb %w1,%b0" : "=a" (Data
) : "d" ((UINT16
)Port
));
55 FilterAfterIoRead (FilterWidth8
, Port
, &Data
);
61 Writes an 8-bit I/O port.
63 Writes the 8-bit I/O port specified by Port with the value specified by Value
64 and returns Value. This function must guarantee that all I/O read and write
65 operations are serialized.
67 If 8-bit I/O port operations are not supported, then ASSERT().
69 For Td guest TDVMCALL_IO is invoked to write I/O port.
71 @param Port The I/O port to write.
72 @param Value The value to write to the I/O port.
74 @return The value written the I/O port.
86 Flag
= FilterBeforeIoWrite (FilterWidth8
, Port
, &Value
);
89 TdIoWrite8 (Port
, Value
);
91 __asm__
__volatile__ ("outb %b0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
95 FilterAfterIoWrite (FilterWidth8
, Port
, &Value
);
101 Reads a 16-bit I/O port.
103 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
104 This function must guarantee that all I/O read and write operations are
107 If 16-bit I/O port operations are not supported, then ASSERT().
108 If Port is not aligned on a 16-bit boundary, then ASSERT().
110 For Td guest TDVMCALL_IO is invoked to read I/O port.
112 @param Port The I/O port to read.
114 @return The value read.
126 ASSERT ((Port
& 1) == 0);
128 Flag
= FilterBeforeIoRead (FilterWidth16
, Port
, &Data
);
131 Data
= TdIoRead16 (Port
);
133 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
137 FilterAfterIoRead (FilterWidth16
, Port
, &Data
);
143 Writes a 16-bit I/O port.
145 Writes the 16-bit I/O port specified by Port with the value specified by Value
146 and returns Value. This function must guarantee that all I/O read and write
147 operations are serialized.
149 If 16-bit I/O port operations are not supported, then ASSERT().
150 If Port is not aligned on a 16-bit boundary, then ASSERT().
152 For Td guest TDVMCALL_IO is invoked to write I/O port.
154 @param Port The I/O port to write.
155 @param Value The value to write to the I/O port.
157 @return The value written the I/O port.
169 ASSERT ((Port
& 1) == 0);
171 Flag
= FilterBeforeIoWrite (FilterWidth16
, Port
, &Value
);
174 TdIoWrite16 (Port
, Value
);
176 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
180 FilterAfterIoWrite (FilterWidth16
, Port
, &Value
);
186 Reads a 32-bit I/O port.
188 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
189 This function must guarantee that all I/O read and write operations are
192 If 32-bit I/O port operations are not supported, then ASSERT().
193 If Port is not aligned on a 32-bit boundary, then ASSERT().
195 For Td guest TDVMCALL_IO is invoked to read I/O port.
197 @param Port The I/O port to read.
199 @return The value read.
211 ASSERT ((Port
& 3) == 0);
213 Flag
= FilterBeforeIoRead (FilterWidth32
, Port
, &Data
);
216 Data
= TdIoRead32 (Port
);
218 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
222 FilterAfterIoRead (FilterWidth32
, Port
, &Data
);
228 Writes a 32-bit I/O port.
230 Writes the 32-bit I/O port specified by Port with the value specified by Value
231 and returns Value. This function must guarantee that all I/O read and write
232 operations are serialized.
234 If 32-bit I/O port operations are not supported, then ASSERT().
235 If Port is not aligned on a 32-bit boundary, then ASSERT().
237 For Td guest TDVMCALL_IO is invoked to write I/O port.
239 @param Port The I/O port to write.
240 @param Value The value to write to the I/O port.
242 @return The value written the I/O port.
254 ASSERT ((Port
& 3) == 0);
256 Flag
= FilterBeforeIoWrite (FilterWidth32
, Port
, &Value
);
259 TdIoWrite32 (Port
, Value
);
261 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
265 FilterAfterIoWrite (FilterWidth32
, Port
, &Value
);