]>
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
);
206 Copy data from system memory to the MMIO region by using 8-bit access.
208 Copy data from system memory specified by Buffer to the MMIO region specified
209 by starting address StartAddress by using 8-bit access. The total number
210 of byte to be copied is specified by Length. Buffer is returned.
212 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
213 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
216 @param StartAddress The starting address for the MMIO region to be copied to.
217 @param Length The size, in bytes, of Buffer.
218 @param Buffer The pointer to a system memory buffer containing the data to write.
226 IN UINTN StartAddress
,
228 IN CONST UINT8
*Buffer
233 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
234 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
236 ReturnBuffer
= (UINT8
*) Buffer
;
238 while (Length
-- != 0) {
239 MmioWrite8 (StartAddress
++, *(Buffer
++));
247 Copy data from system memory to the MMIO region by using 16-bit access.
249 Copy data from system memory specified by Buffer to the MMIO region specified
250 by starting address StartAddress by using 16-bit access. The total number
251 of byte to be copied is specified by Length. Buffer is returned.
253 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
255 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
256 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
258 If Length is not aligned on a 16-bit boundary, then ASSERT().
260 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
262 @param StartAddress The starting address for the MMIO region to be copied to.
263 @param Length The size, in bytes, of Buffer.
264 @param Buffer The pointer to a system memory buffer containing the data to write.
272 IN UINTN StartAddress
,
274 IN CONST UINT16
*Buffer
277 UINT16
*ReturnBuffer
;
279 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
281 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
282 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
284 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
285 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
287 ReturnBuffer
= (UINT16
*) Buffer
;
289 while (Length
!= 0) {
290 MmioWrite16 (StartAddress
, *(Buffer
++));
292 StartAddress
+= sizeof (UINT16
);
293 Length
-= sizeof (UINT16
);
301 Copy data from system memory to the MMIO region by using 32-bit access.
303 Copy data from system memory specified by Buffer to the MMIO region specified
304 by starting address StartAddress by using 32-bit access. The total number
305 of byte to be copied is specified by Length. Buffer is returned.
307 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
309 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
310 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
312 If Length is not aligned on a 32-bit boundary, then ASSERT().
314 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
316 @param StartAddress The starting address for the MMIO region to be copied to.
317 @param Length The size, in bytes, of Buffer.
318 @param Buffer The pointer to a system memory buffer containing the data to write.
326 IN UINTN StartAddress
,
328 IN CONST UINT32
*Buffer
331 UINT32
*ReturnBuffer
;
333 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
335 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
336 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
338 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
339 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
341 ReturnBuffer
= (UINT32
*) Buffer
;
343 while (Length
!= 0) {
344 MmioWrite32 (StartAddress
, *(Buffer
++));
346 StartAddress
+= sizeof (UINT32
);
347 Length
-= sizeof (UINT32
);
354 Copy data from system memory to the MMIO region by using 64-bit access.
356 Copy data from system memory specified by Buffer to the MMIO region specified
357 by starting address StartAddress by using 64-bit access. The total number
358 of byte to be copied is specified by Length. Buffer is returned.
360 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
362 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
363 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
365 If Length is not aligned on a 64-bit boundary, then ASSERT().
367 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
369 @param StartAddress The starting address for the MMIO region to be copied to.
370 @param Length The size, in bytes, of Buffer.
371 @param Buffer The pointer to a system memory buffer containing the data to write.
379 IN UINTN StartAddress
,
381 IN CONST UINT64
*Buffer
384 UINT64
*ReturnBuffer
;
386 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
388 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
389 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
391 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
392 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
394 ReturnBuffer
= (UINT64
*) Buffer
;
396 while (Length
!= 0) {
397 MmioWrite64 (StartAddress
, *(Buffer
++));
399 StartAddress
+= sizeof (UINT64
);
400 Length
-= sizeof (UINT64
);