]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibGcc.c
MdePkg: Apply uncrustify changes
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibGcc.c
1 /** @file
2 I/O Library. This file has compiler specifics for GCC as there is no
3 ANSI C standard for doing IO.
4
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
8 with EFIAPI assembler.
9
10 We don't advocate putting compiler specifics in libraries or drivers but there
11 is no other way to make this work.
12
13 Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
14 SPDX-License-Identifier: BSD-2-Clause-Patent
15
16 **/
17
18 #include "BaseIoLibIntrinsicInternal.h"
19
20 /**
21 Reads an 8-bit I/O port.
22
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
25 serialized.
26
27 If 8-bit I/O port operations are not supported, then ASSERT().
28
29 @param Port The I/O port to read.
30
31 @return The value read.
32
33 **/
34 UINT8
35 EFIAPI
36 IoRead8 (
37 IN UINTN Port
38 )
39 {
40 UINT8 Data;
41 BOOLEAN Flag;
42
43 Flag = FilterBeforeIoRead (FilterWidth8, Port, &Data);
44 if (Flag) {
45 __asm__ __volatile__ ("inb %w1,%b0" : "=a" (Data) : "d" ((UINT16)Port));
46 }
47
48 FilterAfterIoRead (FilterWidth8, Port, &Data);
49
50 return Data;
51 }
52
53 /**
54 Writes an 8-bit I/O port.
55
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.
59
60 If 8-bit I/O port operations are not supported, then ASSERT().
61
62 @param Port The I/O port to write.
63 @param Value The value to write to the I/O port.
64
65 @return The value written the I/O port.
66
67 **/
68 UINT8
69 EFIAPI
70 IoWrite8 (
71 IN UINTN Port,
72 IN UINT8 Value
73 )
74 {
75 BOOLEAN Flag;
76
77 Flag = FilterBeforeIoWrite (FilterWidth8, Port, &Value);
78 if (Flag) {
79 __asm__ __volatile__ ("outb %b0,%w1" : : "a" (Value), "d" ((UINT16)Port));
80 }
81
82 FilterAfterIoWrite (FilterWidth8, Port, &Value);
83
84 return Value;
85 }
86
87 /**
88 Reads a 16-bit I/O port.
89
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
92 serialized.
93
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().
96
97 @param Port The I/O port to read.
98
99 @return The value read.
100
101 **/
102 UINT16
103 EFIAPI
104 IoRead16 (
105 IN UINTN Port
106 )
107 {
108 UINT16 Data;
109 BOOLEAN Flag;
110
111 ASSERT ((Port & 1) == 0);
112
113 Flag = FilterBeforeIoRead (FilterWidth16, Port, &Data);
114 if (Flag) {
115 __asm__ __volatile__ ("inw %w1,%w0" : "=a" (Data) : "d" ((UINT16)Port));
116 }
117
118 FilterAfterIoRead (FilterWidth16, Port, &Data);
119
120 return Data;
121 }
122
123 /**
124 Writes a 16-bit I/O port.
125
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.
129
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().
132
133 @param Port The I/O port to write.
134 @param Value The value to write to the I/O port.
135
136 @return The value written the I/O port.
137
138 **/
139 UINT16
140 EFIAPI
141 IoWrite16 (
142 IN UINTN Port,
143 IN UINT16 Value
144 )
145 {
146 BOOLEAN Flag;
147
148 ASSERT ((Port & 1) == 0);
149
150 Flag = FilterBeforeIoWrite (FilterWidth16, Port, &Value);
151 if (Flag) {
152 __asm__ __volatile__ ("outw %w0,%w1" : : "a" (Value), "d" ((UINT16)Port));
153 }
154
155 FilterAfterIoWrite (FilterWidth16, Port, &Value);
156
157 return Value;
158 }
159
160 /**
161 Reads a 32-bit I/O port.
162
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
165 serialized.
166
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().
169
170 @param Port The I/O port to read.
171
172 @return The value read.
173
174 **/
175 UINT32
176 EFIAPI
177 IoRead32 (
178 IN UINTN Port
179 )
180 {
181 UINT32 Data;
182 BOOLEAN Flag;
183
184 ASSERT ((Port & 3) == 0);
185
186 Flag = FilterBeforeIoRead (FilterWidth32, Port, &Data);
187 if (Flag) {
188 __asm__ __volatile__ ("inl %w1,%0" : "=a" (Data) : "d" ((UINT16)Port));
189 }
190
191 FilterAfterIoRead (FilterWidth32, Port, &Data);
192
193 return Data;
194 }
195
196 /**
197 Writes a 32-bit I/O port.
198
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.
202
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().
205
206 @param Port The I/O port to write.
207 @param Value The value to write to the I/O port.
208
209 @return The value written the I/O port.
210
211 **/
212 UINT32
213 EFIAPI
214 IoWrite32 (
215 IN UINTN Port,
216 IN UINT32 Value
217 )
218 {
219 BOOLEAN Flag;
220
221 ASSERT ((Port & 3) == 0);
222
223 Flag = FilterBeforeIoWrite (FilterWidth32, Port, &Value);
224 if (Flag) {
225 __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));
226 }
227
228 FilterAfterIoWrite (FilterWidth32, Port, &Value);
229
230 return Value;
231 }