]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibGcc.c
5c791289c469111c767318c0bfde0dc96be4e44a
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"
21 Reads an 8-bit I/O port.
23 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
24 This function must guarantee that all I/O read and write operations are
27 If 8-bit I/O port operations are not supported, then ASSERT().
29 @param Port The I/O port to read.
31 @return The value read.
43 Flag
= FilterBeforeIoRead (FilterWidth8
, Port
, &Data
);
45 __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
));
82 FilterAfterIoWrite (FilterWidth8
, Port
, &Value
);
88 Reads a 16-bit I/O port.
90 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
91 This function must guarantee that all I/O read and write operations are
94 If 16-bit I/O port operations are not supported, then ASSERT().
95 If Port is not aligned on a 16-bit boundary, then ASSERT().
97 @param Port The I/O port to read.
99 @return The value read.
111 ASSERT ((Port
& 1) == 0);
113 Flag
= FilterBeforeIoRead (FilterWidth16
, Port
, &Data
);
115 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
118 FilterAfterIoRead (FilterWidth16
, Port
, &Data
);
124 Writes a 16-bit I/O port.
126 Writes the 16-bit I/O port specified by Port with the value specified by Value
127 and returns Value. This function must guarantee that all I/O read and write
128 operations are serialized.
130 If 16-bit I/O port operations are not supported, then ASSERT().
131 If Port is not aligned on a 16-bit boundary, then ASSERT().
133 @param Port The I/O port to write.
134 @param Value The value to write to the I/O port.
136 @return The value written the I/O port.
148 ASSERT ((Port
& 1) == 0);
150 Flag
= FilterBeforeIoWrite (FilterWidth16
, Port
, &Value
);
152 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
155 FilterAfterIoWrite (FilterWidth16
, Port
, &Value
);
161 Reads a 32-bit I/O port.
163 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
164 This function must guarantee that all I/O read and write operations are
167 If 32-bit I/O port operations are not supported, then ASSERT().
168 If Port is not aligned on a 32-bit boundary, then ASSERT().
170 @param Port The I/O port to read.
172 @return The value read.
184 ASSERT ((Port
& 3) == 0);
186 Flag
= FilterBeforeIoRead (FilterWidth32
, Port
, &Data
);
188 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
191 FilterAfterIoRead (FilterWidth32
, Port
, &Data
);
197 Writes a 32-bit I/O port.
199 Writes the 32-bit I/O port specified by Port with the value specified by Value
200 and returns Value. This function must guarantee that all I/O read and write
201 operations are serialized.
203 If 32-bit I/O port operations are not supported, then ASSERT().
204 If Port is not aligned on a 32-bit boundary, then ASSERT().
206 @param Port The I/O port to write.
207 @param Value The value to write to the I/O port.
209 @return The value written the I/O port.
221 ASSERT ((Port
& 3) == 0);
223 Flag
= FilterBeforeIoWrite (FilterWidth32
, Port
, &Value
);
225 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
228 FilterAfterIoWrite (FilterWidth32
, Port
, &Value
);