]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLib.c
MdePkg: Apply uncrustify changes
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLib.c
1 /** @file
2 Common I/O Library routines.
3
4 Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "BaseIoLibIntrinsicInternal.h"
10
11 /**
12 Reads a 64-bit I/O port.
13
14 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
15 This function must guarantee that all I/O read and write operations are
16 serialized.
17
18 If 64-bit I/O port operations are not supported, then ASSERT().
19 If Port is not aligned on a 64-bit boundary, then ASSERT().
20
21 @param Port The I/O port to read.
22
23 @return The value read.
24
25 **/
26 UINT64
27 EFIAPI
28 IoRead64 (
29 IN UINTN Port
30 )
31 {
32 ASSERT (FALSE);
33 return 0;
34 }
35
36 /**
37 Writes a 64-bit I/O port.
38
39 Writes the 64-bit I/O port specified by Port with the value specified by Value
40 and returns Value. This function must guarantee that all I/O read and write
41 operations are serialized.
42
43 If 64-bit I/O port operations are not supported, then ASSERT().
44 If Port is not aligned on a 64-bit boundary, then ASSERT().
45
46 @param Port The I/O port to write.
47 @param Value The value to write to the I/O port.
48
49 @return The value written the I/O port.
50
51 **/
52 UINT64
53 EFIAPI
54 IoWrite64 (
55 IN UINTN Port,
56 IN UINT64 Value
57 )
58 {
59 ASSERT (FALSE);
60 return 0;
61 }
62
63 /**
64 Reads an 8-bit MMIO register.
65
66 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
67 returned. This function must guarantee that all MMIO read and write
68 operations are serialized.
69
70 If 8-bit MMIO register operations are not supported, then ASSERT().
71
72 @param Address The MMIO register to read.
73
74 @return The value read.
75
76 **/
77 UINT8
78 EFIAPI
79 MmioRead8 (
80 IN UINTN Address
81 )
82 {
83 UINT8 Value;
84 BOOLEAN Flag;
85
86 Flag = FilterBeforeMmIoRead (FilterWidth8, Address, &Value);
87 if (Flag) {
88 MemoryFence ();
89 Value = *(volatile UINT8 *)Address;
90 MemoryFence ();
91 }
92
93 FilterAfterMmIoRead (FilterWidth8, Address, &Value);
94
95 return Value;
96 }
97
98 /**
99 Writes an 8-bit MMIO register.
100
101 Writes the 8-bit MMIO register specified by Address with the value specified
102 by Value and returns Value. This function must guarantee that all MMIO read
103 and write operations are serialized.
104
105 If 8-bit MMIO register operations are not supported, then ASSERT().
106
107 @param Address The MMIO register to write.
108 @param Value The value to write to the MMIO register.
109
110 @return Value.
111
112 **/
113 UINT8
114 EFIAPI
115 MmioWrite8 (
116 IN UINTN Address,
117 IN UINT8 Value
118 )
119 {
120 BOOLEAN Flag;
121
122 Flag = FilterBeforeMmIoWrite (FilterWidth8, Address, &Value);
123 if (Flag) {
124 MemoryFence ();
125 *(volatile UINT8 *)Address = Value;
126 MemoryFence ();
127 }
128
129 FilterAfterMmIoWrite (FilterWidth8, Address, &Value);
130
131 return Value;
132 }
133
134 /**
135 Reads a 16-bit MMIO register.
136
137 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
138 returned. This function must guarantee that all MMIO read and write
139 operations are serialized.
140
141 If 16-bit MMIO register operations are not supported, then ASSERT().
142 If Address is not aligned on a 16-bit boundary, then ASSERT().
143
144 @param Address The MMIO register to read.
145
146 @return The value read.
147
148 **/
149 UINT16
150 EFIAPI
151 MmioRead16 (
152 IN UINTN Address
153 )
154 {
155 UINT16 Value;
156 BOOLEAN Flag;
157
158 ASSERT ((Address & 1) == 0);
159 Flag = FilterBeforeMmIoRead (FilterWidth16, Address, &Value);
160 if (Flag) {
161 MemoryFence ();
162 Value = *(volatile UINT16 *)Address;
163 MemoryFence ();
164 }
165
166 FilterAfterMmIoRead (FilterWidth16, Address, &Value);
167
168 return Value;
169 }
170
171 /**
172 Writes a 16-bit MMIO register.
173
174 Writes the 16-bit MMIO register specified by Address with the value specified
175 by Value and returns Value. This function must guarantee that all MMIO read
176 and write operations are serialized.
177
178 If 16-bit MMIO register operations are not supported, then ASSERT().
179 If Address is not aligned on a 16-bit boundary, then ASSERT().
180
181 @param Address The MMIO register to write.
182 @param Value The value to write to the MMIO register.
183
184 @return Value.
185
186 **/
187 UINT16
188 EFIAPI
189 MmioWrite16 (
190 IN UINTN Address,
191 IN UINT16 Value
192 )
193 {
194 BOOLEAN Flag;
195
196 ASSERT ((Address & 1) == 0);
197
198 Flag = FilterBeforeMmIoWrite (FilterWidth16, Address, &Value);
199 if (Flag) {
200 MemoryFence ();
201 *(volatile UINT16 *)Address = Value;
202 MemoryFence ();
203 }
204
205 FilterAfterMmIoWrite (FilterWidth16, Address, &Value);
206
207 return Value;
208 }
209
210 /**
211 Reads a 32-bit MMIO register.
212
213 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
214 returned. This function must guarantee that all MMIO read and write
215 operations are serialized.
216
217 If 32-bit MMIO register operations are not supported, then ASSERT().
218 If Address is not aligned on a 32-bit boundary, then ASSERT().
219
220 @param Address The MMIO register to read.
221
222 @return The value read.
223
224 **/
225 UINT32
226 EFIAPI
227 MmioRead32 (
228 IN UINTN Address
229 )
230 {
231 UINT32 Value;
232 BOOLEAN Flag;
233
234 ASSERT ((Address & 3) == 0);
235
236 Flag = FilterBeforeMmIoRead (FilterWidth32, Address, &Value);
237 if (Flag) {
238 MemoryFence ();
239 Value = *(volatile UINT32 *)Address;
240 MemoryFence ();
241 }
242
243 FilterAfterMmIoRead (FilterWidth32, Address, &Value);
244
245 return Value;
246 }
247
248 /**
249 Writes a 32-bit MMIO register.
250
251 Writes the 32-bit MMIO register specified by Address with the value specified
252 by Value and returns Value. This function must guarantee that all MMIO read
253 and write operations are serialized.
254
255 If 32-bit MMIO register operations are not supported, then ASSERT().
256 If Address is not aligned on a 32-bit boundary, then ASSERT().
257
258 @param Address The MMIO register to write.
259 @param Value The value to write to the MMIO register.
260
261 @return Value.
262
263 **/
264 UINT32
265 EFIAPI
266 MmioWrite32 (
267 IN UINTN Address,
268 IN UINT32 Value
269 )
270 {
271 BOOLEAN Flag;
272
273 ASSERT ((Address & 3) == 0);
274
275 Flag = FilterBeforeMmIoWrite (FilterWidth32, Address, &Value);
276 if (Flag) {
277 MemoryFence ();
278 *(volatile UINT32 *)Address = Value;
279 MemoryFence ();
280 }
281
282 FilterAfterMmIoWrite (FilterWidth32, Address, &Value);
283
284 return Value;
285 }
286
287 /**
288 Reads a 64-bit MMIO register.
289
290 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
291 returned. This function must guarantee that all MMIO read and write
292 operations are serialized.
293
294 If 64-bit MMIO register operations are not supported, then ASSERT().
295 If Address is not aligned on a 64-bit boundary, then ASSERT().
296
297 @param Address The MMIO register to read.
298
299 @return The value read.
300
301 **/
302 UINT64
303 EFIAPI
304 MmioRead64 (
305 IN UINTN Address
306 )
307 {
308 UINT64 Value;
309 BOOLEAN Flag;
310
311 ASSERT ((Address & 7) == 0);
312
313 Flag = FilterBeforeMmIoRead (FilterWidth64, Address, &Value);
314 if (Flag) {
315 MemoryFence ();
316 Value = *(volatile UINT64 *)Address;
317 MemoryFence ();
318 }
319
320 FilterAfterMmIoRead (FilterWidth64, Address, &Value);
321
322 return Value;
323 }
324
325 /**
326 Writes a 64-bit MMIO register.
327
328 Writes the 64-bit MMIO register specified by Address with the value specified
329 by Value and returns Value. This function must guarantee that all MMIO read
330 and write operations are serialized.
331
332 If 64-bit MMIO register operations are not supported, then ASSERT().
333 If Address is not aligned on a 64-bit boundary, then ASSERT().
334
335 @param Address The MMIO register to write.
336 @param Value The value to write to the MMIO register.
337
338 **/
339 UINT64
340 EFIAPI
341 MmioWrite64 (
342 IN UINTN Address,
343 IN UINT64 Value
344 )
345 {
346 BOOLEAN Flag;
347
348 ASSERT ((Address & 7) == 0);
349
350 Flag = FilterBeforeMmIoWrite (FilterWidth64, Address, &Value);
351 if (Flag) {
352 MemoryFence ();
353 *(volatile UINT64 *)Address = Value;
354 MemoryFence ();
355 }
356
357 FilterAfterMmIoWrite (FilterWidth64, Address, &Value);
358
359 return Value;
360 }