]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLib.c
a6bbc925462b2c1c1172d0cc702af4484e442aef
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLib.c
1 /** @file
2 Common I/O Library routines.
3
4 Copyright (c) 2006 - 2018, 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 /**
65 Reads an 8-bit MMIO register.
66
67 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
68 returned. This function must guarantee that all MMIO read and write
69 operations are serialized.
70
71 If 8-bit MMIO register operations are not supported, then ASSERT().
72
73 @param Address The MMIO register to read.
74
75 @return The value read.
76
77 **/
78 UINT8
79 EFIAPI
80 MmioRead8 (
81 IN UINTN Address
82 )
83 {
84 UINT8 Value;
85
86 MemoryFence ();
87 Value = *(volatile UINT8*)Address;
88 MemoryFence ();
89
90 return Value;
91 }
92
93 /**
94 Writes an 8-bit MMIO register.
95
96 Writes the 8-bit MMIO register specified by Address with the value specified
97 by Value and returns Value. This function must guarantee that all MMIO read
98 and write operations are serialized.
99
100 If 8-bit MMIO register operations are not supported, then ASSERT().
101
102 @param Address The MMIO register to write.
103 @param Value The value to write to the MMIO register.
104
105 @return Value.
106
107 **/
108 UINT8
109 EFIAPI
110 MmioWrite8 (
111 IN UINTN Address,
112 IN UINT8 Value
113 )
114 {
115 MemoryFence ();
116 *(volatile UINT8*)Address = Value;
117 MemoryFence ();
118
119 return Value;
120 }
121
122 /**
123 Reads a 16-bit MMIO register.
124
125 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
126 returned. This function must guarantee that all MMIO read and write
127 operations are serialized.
128
129 If 16-bit MMIO register operations are not supported, then ASSERT().
130 If Address is not aligned on a 16-bit boundary, then ASSERT().
131
132 @param Address The MMIO register to read.
133
134 @return The value read.
135
136 **/
137 UINT16
138 EFIAPI
139 MmioRead16 (
140 IN UINTN Address
141 )
142 {
143 UINT16 Value;
144
145 ASSERT ((Address & 1) == 0);
146
147 MemoryFence ();
148 Value = *(volatile UINT16*)Address;
149 MemoryFence ();
150
151 return Value;
152 }
153
154 /**
155 Writes a 16-bit MMIO register.
156
157 Writes the 16-bit MMIO register specified by Address with the value specified
158 by Value and returns Value. This function must guarantee that all MMIO read
159 and write operations are serialized.
160
161 If 16-bit MMIO register operations are not supported, then ASSERT().
162 If Address is not aligned on a 16-bit boundary, then ASSERT().
163
164 @param Address The MMIO register to write.
165 @param Value The value to write to the MMIO register.
166
167 @return Value.
168
169 **/
170 UINT16
171 EFIAPI
172 MmioWrite16 (
173 IN UINTN Address,
174 IN UINT16 Value
175 )
176 {
177 ASSERT ((Address & 1) == 0);
178
179 MemoryFence ();
180 *(volatile UINT16*)Address = Value;
181 MemoryFence ();
182
183 return Value;
184 }
185
186 /**
187 Reads a 32-bit MMIO register.
188
189 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
190 returned. This function must guarantee that all MMIO read and write
191 operations are serialized.
192
193 If 32-bit MMIO register operations are not supported, then ASSERT().
194 If Address is not aligned on a 32-bit boundary, then ASSERT().
195
196 @param Address The MMIO register to read.
197
198 @return The value read.
199
200 **/
201 UINT32
202 EFIAPI
203 MmioRead32 (
204 IN UINTN Address
205 )
206 {
207 UINT32 Value;
208
209 ASSERT ((Address & 3) == 0);
210
211 MemoryFence ();
212 Value = *(volatile UINT32*)Address;
213 MemoryFence ();
214
215 return Value;
216 }
217
218 /**
219 Writes a 32-bit MMIO register.
220
221 Writes the 32-bit MMIO register specified by Address with the value specified
222 by Value and returns Value. This function must guarantee that all MMIO read
223 and write operations are serialized.
224
225 If 32-bit MMIO register operations are not supported, then ASSERT().
226 If Address is not aligned on a 32-bit boundary, then ASSERT().
227
228 @param Address The MMIO register to write.
229 @param Value The value to write to the MMIO register.
230
231 @return Value.
232
233 **/
234 UINT32
235 EFIAPI
236 MmioWrite32 (
237 IN UINTN Address,
238 IN UINT32 Value
239 )
240 {
241 ASSERT ((Address & 3) == 0);
242
243 MemoryFence ();
244 *(volatile UINT32*)Address = Value;
245 MemoryFence ();
246
247 return Value;
248 }
249
250 /**
251 Reads a 64-bit MMIO register.
252
253 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
254 returned. This function must guarantee that all MMIO read and write
255 operations are serialized.
256
257 If 64-bit MMIO register operations are not supported, then ASSERT().
258 If Address is not aligned on a 64-bit boundary, then ASSERT().
259
260 @param Address The MMIO register to read.
261
262 @return The value read.
263
264 **/
265 UINT64
266 EFIAPI
267 MmioRead64 (
268 IN UINTN Address
269 )
270 {
271 UINT64 Value;
272
273 ASSERT ((Address & 7) == 0);
274
275 MemoryFence ();
276 Value = *(volatile UINT64*)Address;
277 MemoryFence ();
278
279 return Value;
280 }
281
282 /**
283 Writes a 64-bit MMIO register.
284
285 Writes the 64-bit MMIO register specified by Address with the value specified
286 by Value and returns Value. This function must guarantee that all MMIO read
287 and write operations are serialized.
288
289 If 64-bit MMIO register operations are not supported, then ASSERT().
290 If Address is not aligned on a 64-bit boundary, then ASSERT().
291
292 @param Address The MMIO register to write.
293 @param Value The value to write to the MMIO register.
294
295 **/
296 UINT64
297 EFIAPI
298 MmioWrite64 (
299 IN UINTN Address,
300 IN UINT64 Value
301 )
302 {
303 ASSERT ((Address & 7) == 0);
304
305 MemoryFence ();
306 *(volatile UINT64*)Address = Value;
307 MemoryFence ();
308
309 return Value;
310 }
311