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