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