]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibMmioBuffer.c
2 I/O Library MMIO Buffer Functions.
4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "BaseIoLibIntrinsicInternal.h"
12 Copy data from the MMIO region to system memory by using 8-bit access.
14 Copy data from the MMIO region specified by starting address StartAddress
15 to system memory specified by Buffer by using 8-bit access. The total
16 number of byte to be copied is specified by Length. Buffer is returned.
18 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
19 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
22 @param StartAddress The starting address for the MMIO region to be copied from.
23 @param Length The size, in bytes, of Buffer.
24 @param Buffer The pointer to a system memory buffer receiving the data read.
32 IN UINTN StartAddress
,
39 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
40 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
42 ReturnBuffer
= Buffer
;
44 while (Length
-- != 0) {
45 *(Buffer
++) = MmioRead8 (StartAddress
++);
52 Copy data from the MMIO region to system memory by using 16-bit access.
54 Copy data from the MMIO region specified by starting address StartAddress
55 to system memory specified by Buffer by using 16-bit access. The total
56 number of byte to be copied is specified by Length. Buffer is returned.
58 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
60 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
61 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
63 If Length is not aligned on a 16-bit boundary, then ASSERT().
64 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
66 @param StartAddress The starting address for the MMIO region to be copied from.
67 @param Length The size, in bytes, of Buffer.
68 @param Buffer The pointer to a system memory buffer receiving the data read.
76 IN UINTN StartAddress
,
83 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
85 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
86 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
88 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
89 ASSERT (((UINTN
)Buffer
& (sizeof (UINT16
) - 1)) == 0);
91 ReturnBuffer
= Buffer
;
94 *(Buffer
++) = MmioRead16 (StartAddress
);
95 StartAddress
+= sizeof (UINT16
);
96 Length
-= sizeof (UINT16
);
103 Copy data from the MMIO region to system memory by using 32-bit access.
105 Copy data from the MMIO region specified by starting address StartAddress
106 to system memory specified by Buffer by using 32-bit access. The total
107 number of byte to be copied is specified by Length. Buffer is returned.
109 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
111 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
112 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
114 If Length is not aligned on a 32-bit boundary, then ASSERT().
115 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
117 @param StartAddress The starting address for the MMIO region to be copied from.
118 @param Length The size, in bytes, of Buffer.
119 @param Buffer The pointer to a system memory buffer receiving the data read.
127 IN UINTN StartAddress
,
132 UINT32
*ReturnBuffer
;
134 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
136 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
137 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
139 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
140 ASSERT (((UINTN
)Buffer
& (sizeof (UINT32
) - 1)) == 0);
142 ReturnBuffer
= Buffer
;
144 while (Length
!= 0) {
145 *(Buffer
++) = MmioRead32 (StartAddress
);
146 StartAddress
+= sizeof (UINT32
);
147 Length
-= sizeof (UINT32
);
154 Copy data from the MMIO region to system memory by using 64-bit access.
156 Copy data from the MMIO region specified by starting address StartAddress
157 to system memory specified by Buffer by using 64-bit access. The total
158 number of byte to be copied is specified by Length. Buffer is returned.
160 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
162 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
163 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
165 If Length is not aligned on a 64-bit boundary, then ASSERT().
166 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
168 @param StartAddress The starting address for the MMIO region to be copied from.
169 @param Length The size, in bytes, of Buffer.
170 @param Buffer The pointer to a system memory buffer receiving the data read.
178 IN UINTN StartAddress
,
183 UINT64
*ReturnBuffer
;
185 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
187 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
188 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
190 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
191 ASSERT (((UINTN
)Buffer
& (sizeof (UINT64
) - 1)) == 0);
193 ReturnBuffer
= Buffer
;
195 while (Length
!= 0) {
196 *(Buffer
++) = MmioRead64 (StartAddress
);
197 StartAddress
+= sizeof (UINT64
);
198 Length
-= sizeof (UINT64
);
205 Copy data from system memory to the MMIO region by using 8-bit access.
207 Copy data from system memory specified by Buffer to the MMIO region specified
208 by starting address StartAddress by using 8-bit access. The total number
209 of byte to be copied is specified by Length. Buffer is returned.
211 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
212 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
215 @param StartAddress The starting address for the MMIO region to be copied to.
216 @param Length The size, in bytes, of Buffer.
217 @param Buffer The pointer to a system memory buffer containing the data to write.
225 IN UINTN StartAddress
,
227 IN CONST UINT8
*Buffer
232 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
233 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
235 ReturnBuffer
= (UINT8
*)Buffer
;
237 while (Length
-- != 0) {
238 MmioWrite8 (StartAddress
++, *(Buffer
++));
245 Copy data from system memory to the MMIO region by using 16-bit access.
247 Copy data from system memory specified by Buffer to the MMIO region specified
248 by starting address StartAddress by using 16-bit access. The total number
249 of byte to be copied is specified by Length. Buffer is returned.
251 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
253 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
254 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
256 If Length is not aligned on a 16-bit boundary, then ASSERT().
258 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
260 @param StartAddress The starting address for the MMIO region to be copied to.
261 @param Length The size, in bytes, of Buffer.
262 @param Buffer The pointer to a system memory buffer containing the data to write.
270 IN UINTN StartAddress
,
272 IN CONST UINT16
*Buffer
275 UINT16
*ReturnBuffer
;
277 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
279 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
280 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
282 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
283 ASSERT (((UINTN
)Buffer
& (sizeof (UINT16
) - 1)) == 0);
285 ReturnBuffer
= (UINT16
*)Buffer
;
287 while (Length
!= 0) {
288 MmioWrite16 (StartAddress
, *(Buffer
++));
290 StartAddress
+= sizeof (UINT16
);
291 Length
-= sizeof (UINT16
);
298 Copy data from system memory to the MMIO region by using 32-bit access.
300 Copy data from system memory specified by Buffer to the MMIO region specified
301 by starting address StartAddress by using 32-bit access. The total number
302 of byte to be copied is specified by Length. Buffer is returned.
304 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
306 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
307 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
309 If Length is not aligned on a 32-bit boundary, then ASSERT().
311 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
313 @param StartAddress The starting address for the MMIO region to be copied to.
314 @param Length The size, in bytes, of Buffer.
315 @param Buffer The pointer to a system memory buffer containing the data to write.
323 IN UINTN StartAddress
,
325 IN CONST UINT32
*Buffer
328 UINT32
*ReturnBuffer
;
330 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
332 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
333 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
335 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
336 ASSERT (((UINTN
)Buffer
& (sizeof (UINT32
) - 1)) == 0);
338 ReturnBuffer
= (UINT32
*)Buffer
;
340 while (Length
!= 0) {
341 MmioWrite32 (StartAddress
, *(Buffer
++));
343 StartAddress
+= sizeof (UINT32
);
344 Length
-= sizeof (UINT32
);
351 Copy data from system memory to the MMIO region by using 64-bit access.
353 Copy data from system memory specified by Buffer to the MMIO region specified
354 by starting address StartAddress by using 64-bit access. The total number
355 of byte to be copied is specified by Length. Buffer is returned.
357 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
359 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
360 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
362 If Length is not aligned on a 64-bit boundary, then ASSERT().
364 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
366 @param StartAddress The starting address for the MMIO region to be copied to.
367 @param Length The size, in bytes, of Buffer.
368 @param Buffer The pointer to a system memory buffer containing the data to write.
376 IN UINTN StartAddress
,
378 IN CONST UINT64
*Buffer
381 UINT64
*ReturnBuffer
;
383 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
385 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
386 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
388 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
389 ASSERT (((UINTN
)Buffer
& (sizeof (UINT64
) - 1)) == 0);
391 ReturnBuffer
= (UINT64
*)Buffer
;
393 while (Length
!= 0) {
394 MmioWrite64 (StartAddress
, *(Buffer
++));
396 StartAddress
+= sizeof (UINT64
);
397 Length
-= sizeof (UINT64
);