]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkPkg/Library/DxeIoLibCpuIo/IoLibMmioBuffer.c
MdeModulePkg/FaultTolerantWriteDxe: implement standalone MM version
[mirror_edk2.git] / IntelFrameworkPkg / Library / DxeIoLibCpuIo / IoLibMmioBuffer.c
CommitLineData
79964ac8 1/** @file\r
2 I/O Library MMIO Buffer Functions.\r
3\r
1c2f052d 4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
2b3687db 5 This program and the accompanying materials\r
79964ac8 6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
596cecff 13 Module Name: IoLibMmioBuffer.c\r
14\r
79964ac8 15**/\r
16\r
694363f8 17\r
79964ac8 18#include "DxeCpuIoLibInternal.h"\r
19\r
20/**\r
21 Copy data from MMIO region to system memory by using 8-bit access.\r
22\r
23 Copy data from MMIO region specified by starting address StartAddress\r
24 to system memory specified by Buffer by using 8-bit access. The total\r
25 number of byte to be copied is specified by Length. Buffer is returned.\r
26\r
27 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
28 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
29\r
30\r
31 @param StartAddress Starting address for the MMIO region to be copied from.\r
32 @param Length Size in bytes of the copy.\r
33 @param Buffer Pointer to a system memory buffer receiving the data read.\r
34\r
35 @return Buffer\r
36\r
37**/\r
38UINT8 *\r
39EFIAPI\r
40MmioReadBuffer8 (\r
41 IN UINTN StartAddress,\r
42 IN UINTN Length,\r
43 OUT UINT8 *Buffer\r
44 )\r
45{\r
46 UINT8 *ReturnBuffer;\r
47\r
48 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
49 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
50\r
51 ReturnBuffer = Buffer;\r
52\r
4ebb0d9e 53 while (Length-- > 0) {\r
79964ac8 54 *(Buffer++) = MmioRead8 (StartAddress++);\r
55 }\r
56\r
57 return ReturnBuffer;\r
58}\r
59\r
60/**\r
61 Copy data from MMIO region to system memory by using 16-bit access.\r
62\r
63 Copy data from MMIO region specified by starting address StartAddress\r
64 to system memory specified by Buffer by using 16-bit access. The total\r
65 number of byte to be copied is specified by Length. Buffer is returned.\r
66\r
67 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().\r
68\r
69 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
70 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
71\r
72 If Length is not aligned on a 16-bit boundary, then ASSERT().\r
1c2f052d 73\r
79964ac8 74 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
75\r
76 @param StartAddress Starting address for the MMIO region to be copied from.\r
77 @param Length Size in bytes of the copy.\r
78 @param Buffer Pointer to a system memory buffer receiving the data read.\r
79\r
80 @return Buffer\r
81\r
82**/\r
83UINT16 *\r
84EFIAPI\r
85MmioReadBuffer16 (\r
86 IN UINTN StartAddress,\r
87 IN UINTN Length,\r
88 OUT UINT16 *Buffer\r
89 )\r
90{\r
91 UINT16 *ReturnBuffer;\r
92\r
93 ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);\r
94\r
95 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
96 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
97\r
98 ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);\r
99 ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);\r
100\r
101 ReturnBuffer = Buffer;\r
102\r
4ebb0d9e 103 while (Length > 0) {\r
79964ac8 104 *(Buffer++) = MmioRead16 (StartAddress);\r
105 StartAddress += sizeof (UINT16);\r
106 Length -= sizeof (UINT16);\r
107 }\r
108\r
109 return ReturnBuffer;\r
110}\r
111\r
112/**\r
113 Copy data from MMIO region to system memory by using 32-bit access.\r
114\r
115 Copy data from MMIO region specified by starting address StartAddress\r
116 to system memory specified by Buffer by using 32-bit access. The total\r
117 number of byte to be copied is specified by Length. Buffer is returned.\r
118\r
119 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().\r
120\r
121 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
122 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
123\r
124 If Length is not aligned on a 32-bit boundary, then ASSERT().\r
125 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
126\r
127 @param StartAddress Starting address for the MMIO region to be copied from.\r
128 @param Length Size in bytes of the copy.\r
129 @param Buffer Pointer to a system memory buffer receiving the data read.\r
130\r
131 @return Buffer\r
132\r
133**/\r
134UINT32 *\r
135EFIAPI\r
136MmioReadBuffer32 (\r
137 IN UINTN StartAddress,\r
138 IN UINTN Length,\r
139 OUT UINT32 *Buffer\r
140 )\r
141{\r
142 UINT32 *ReturnBuffer;\r
143\r
144 ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);\r
145\r
146 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
147 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
148\r
149 ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);\r
150 ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);\r
151\r
152 ReturnBuffer = Buffer;\r
153\r
4ebb0d9e 154 while (Length > 0) {\r
79964ac8 155 *(Buffer++) = MmioRead32 (StartAddress);\r
156 StartAddress += sizeof (UINT32);\r
157 Length -= sizeof (UINT32);\r
158 }\r
159\r
160 return ReturnBuffer;\r
161}\r
162\r
163/**\r
164 Copy data from MMIO region to system memory by using 64-bit access.\r
165\r
166 Copy data from MMIO region specified by starting address StartAddress\r
167 to system memory specified by Buffer by using 64-bit access. The total\r
168 number of byte to be copied is specified by Length. Buffer is returned.\r
169\r
170 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().\r
171\r
172 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
173 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
174\r
175 If Length is not aligned on a 64-bit boundary, then ASSERT().\r
1c2f052d 176\r
79964ac8 177 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
178\r
179 @param StartAddress Starting address for the MMIO region to be copied from.\r
180 @param Length Size in bytes of the copy.\r
181 @param Buffer Pointer to a system memory buffer receiving the data read.\r
182\r
183 @return Buffer\r
184\r
185**/\r
186UINT64 *\r
187EFIAPI\r
188MmioReadBuffer64 (\r
189 IN UINTN StartAddress,\r
190 IN UINTN Length,\r
191 OUT UINT64 *Buffer\r
192 )\r
193{\r
194 UINT64 *ReturnBuffer;\r
195\r
196 ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);\r
197\r
198 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
199 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
200\r
201 ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);\r
202 ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);\r
203\r
204 ReturnBuffer = Buffer;\r
205\r
4ebb0d9e 206 while (Length > 0) {\r
79964ac8 207 *(Buffer++) = MmioRead64 (StartAddress);\r
208 StartAddress += sizeof (UINT64);\r
209 Length -= sizeof (UINT64);\r
210 }\r
211\r
212 return ReturnBuffer;\r
213}\r
214\r
215\r
216/**\r
217 Copy data from system memory to MMIO region by using 8-bit access.\r
218\r
219 Copy data from system memory specified by Buffer to MMIO region specified\r
220 by starting address StartAddress by using 8-bit access. The total number\r
221 of byte to be copied is specified by Length. Buffer is returned.\r
222\r
223 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
224 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
225\r
226\r
227 @param StartAddress Starting address for the MMIO region to be copied to.\r
228 @param Length Size in bytes of the copy.\r
229 @param Buffer Pointer to a system memory buffer containing the data to write.\r
230\r
6bfc419e 231 @return Buffer\r
79964ac8 232\r
233**/\r
234UINT8 *\r
235EFIAPI\r
236MmioWriteBuffer8 (\r
237 IN UINTN StartAddress,\r
238 IN UINTN Length,\r
239 IN CONST UINT8 *Buffer\r
240 )\r
241{\r
242 VOID* ReturnBuffer;\r
243\r
244 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
245 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
246\r
247 ReturnBuffer = (UINT8 *) Buffer;\r
248\r
4ebb0d9e 249 while (Length-- > 0) {\r
79964ac8 250 MmioWrite8 (StartAddress++, *(Buffer++));\r
251 }\r
252\r
253 return ReturnBuffer;\r
254\r
255}\r
256\r
257/**\r
258 Copy data from system memory to MMIO region by using 16-bit access.\r
259\r
260 Copy data from system memory specified by Buffer to MMIO region specified\r
261 by starting address StartAddress by using 16-bit access. The total number\r
6bfc419e 262 of byte to be copied is specified by Length. Buffer is returned.\r
79964ac8 263\r
264 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().\r
265\r
266 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
267 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
268\r
269 If Length is not aligned on a 16-bit boundary, then ASSERT().\r
270\r
271 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
272\r
273 @param StartAddress Starting address for the MMIO region to be copied to.\r
274 @param Length Size in bytes of the copy.\r
275 @param Buffer Pointer to a system memory buffer containing the data to write.\r
276\r
6bfc419e 277 @return Buffer\r
79964ac8 278\r
279**/\r
280UINT16 *\r
281EFIAPI\r
282MmioWriteBuffer16 (\r
283 IN UINTN StartAddress,\r
284 IN UINTN Length,\r
285 IN CONST UINT16 *Buffer\r
286 )\r
287{\r
288 UINT16 *ReturnBuffer;\r
289\r
290 ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);\r
291\r
292 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
293 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
294\r
295 ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);\r
296 ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);\r
297\r
298 ReturnBuffer = (UINT16 *) Buffer;\r
299\r
4ebb0d9e 300 while (Length > 0) {\r
79964ac8 301 MmioWrite16 (StartAddress, *(Buffer++));\r
302\r
303 StartAddress += sizeof (UINT16);\r
304 Length -= sizeof (UINT16);\r
305 }\r
306\r
307 return ReturnBuffer;\r
308}\r
309\r
310\r
311/**\r
312 Copy data from system memory to MMIO region by using 32-bit access.\r
313\r
314 Copy data from system memory specified by Buffer to MMIO region specified\r
315 by starting address StartAddress by using 32-bit access. The total number\r
6bfc419e 316 of byte to be copied is specified by Length. Buffer is returned.\r
79964ac8 317\r
318 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().\r
319\r
320 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
321 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
322\r
323 If Length is not aligned on a 32-bit boundary, then ASSERT().\r
324\r
325 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
326\r
327 @param StartAddress Starting address for the MMIO region to be copied to.\r
328 @param Length Size in bytes of the copy.\r
329 @param Buffer Pointer to a system memory buffer containing the data to write.\r
330\r
6bfc419e 331 @return Buffer\r
79964ac8 332\r
333**/\r
334UINT32 *\r
335EFIAPI\r
336MmioWriteBuffer32 (\r
337 IN UINTN StartAddress,\r
338 IN UINTN Length,\r
339 IN CONST UINT32 *Buffer\r
340 )\r
341{\r
342 UINT32 *ReturnBuffer;\r
343\r
344 ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);\r
345\r
346 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
347 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
348\r
349 ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);\r
350 ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);\r
351\r
352 ReturnBuffer = (UINT32 *) Buffer;\r
353\r
4ebb0d9e 354 while (Length > 0) {\r
79964ac8 355 MmioWrite32 (StartAddress, *(Buffer++));\r
356\r
357 StartAddress += sizeof (UINT32);\r
358 Length -= sizeof (UINT32);\r
359 }\r
360\r
361 return ReturnBuffer;\r
362}\r
363\r
364/**\r
365 Copy data from system memory to MMIO region by using 64-bit access.\r
366\r
367 Copy data from system memory specified by Buffer to MMIO region specified\r
368 by starting address StartAddress by using 64-bit access. The total number\r
6bfc419e 369 of byte to be copied is specified by Length. Buffer is returned.\r
79964ac8 370\r
371 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().\r
372\r
373 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
374 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
375\r
376 If Length is not aligned on a 64-bit boundary, then ASSERT().\r
377\r
378 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
379\r
380 @param StartAddress Starting address for the MMIO region to be copied to.\r
381 @param Length Size in bytes of the copy.\r
382 @param Buffer Pointer to a system memory buffer containing the data to write.\r
383\r
6bfc419e 384 @return Buffer\r
79964ac8 385\r
386**/\r
387UINT64 *\r
388EFIAPI\r
389MmioWriteBuffer64 (\r
390 IN UINTN StartAddress,\r
391 IN UINTN Length,\r
392 IN CONST UINT64 *Buffer\r
393 )\r
394{\r
395 UINT64 *ReturnBuffer;\r
396\r
397 ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);\r
398\r
399 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
400 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
401\r
402 ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);\r
403 ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);\r
404\r
405 ReturnBuffer = (UINT64 *) Buffer;\r
406\r
4ebb0d9e 407 while (Length > 0) {\r
79964ac8 408 MmioWrite64 (StartAddress, *(Buffer++));\r
409\r
410 StartAddress += sizeof (UINT64);\r
411 Length -= sizeof (UINT64);\r
412 }\r
413\r
414 return ReturnBuffer;\r
415}\r
416\r