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