]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeIoLibCpuIo2/IoLibMmioBuffer.c
2731bcdac35258f702bf251465bc2f83942d2e08
2 I/O Library MMIO Buffer Functions.
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "DxeCpuIo2LibInternal.h"
12 Copy data from MMIO region to system memory by using 8-bit access.
14 Copy data from 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 the copy.
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 MMIO region to system memory by using 16-bit access.
54 Copy data from 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().
65 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
67 @param StartAddress The starting address for the MMIO region to be copied from.
68 @param Length The size in bytes of the copy.
69 @param Buffer The pointer to a system memory buffer receiving the data read.
77 IN UINTN StartAddress
,
84 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
86 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
87 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
89 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
90 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
92 ReturnBuffer
= Buffer
;
95 *(Buffer
++) = MmioRead16 (StartAddress
);
96 StartAddress
+= sizeof (UINT16
);
97 Length
-= sizeof (UINT16
);
104 Copy data from MMIO region to system memory by using 32-bit access.
106 Copy data from MMIO region specified by starting address StartAddress
107 to system memory specified by Buffer by using 32-bit access. The total
108 number of byte to be copied is specified by Length. Buffer is returned.
110 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
112 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
113 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
115 If Length is not aligned on a 32-bit boundary, then ASSERT().
116 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
118 @param StartAddress The starting address for the MMIO region to be copied from.
119 @param Length The size in bytes of the copy.
120 @param Buffer The pointer to a system memory buffer receiving the data read.
128 IN UINTN StartAddress
,
133 UINT32
*ReturnBuffer
;
135 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
137 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
138 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
140 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
141 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
143 ReturnBuffer
= Buffer
;
146 *(Buffer
++) = MmioRead32 (StartAddress
);
147 StartAddress
+= sizeof (UINT32
);
148 Length
-= sizeof (UINT32
);
155 Copy data from MMIO region to system memory by using 64-bit access.
157 Copy data from MMIO region specified by starting address StartAddress
158 to system memory specified by Buffer by using 64-bit access. The total
159 number of byte to be copied is specified by Length. Buffer is returned.
161 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
163 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
164 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
166 If Length is not aligned on a 64-bit boundary, then ASSERT().
168 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
170 @param StartAddress The starting address for the MMIO region to be copied from.
171 @param Length The size in bytes of the copy.
172 @param Buffer The pointer to a system memory buffer receiving the data read.
180 IN UINTN StartAddress
,
185 UINT64
*ReturnBuffer
;
187 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
189 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
190 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
192 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
193 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
195 ReturnBuffer
= Buffer
;
198 *(Buffer
++) = MmioRead64 (StartAddress
);
199 StartAddress
+= sizeof (UINT64
);
200 Length
-= sizeof (UINT64
);
208 Copy data from system memory to MMIO region by using 8-bit access.
210 Copy data from system memory specified by Buffer to MMIO region specified
211 by starting address StartAddress by using 8-bit access. The total number
212 of byte to be copied is specified by Length. Buffer is returned.
214 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
215 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
218 @param StartAddress The starting address for the MMIO region to be copied to.
219 @param Length The size in bytes of the copy.
220 @param Buffer The pointer to a system memory buffer containing the data to write.
228 IN UINTN StartAddress
,
230 IN CONST UINT8
*Buffer
235 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
236 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
238 ReturnBuffer
= (UINT8
*) Buffer
;
240 while (Length
-- > 0) {
241 MmioWrite8 (StartAddress
++, *(Buffer
++));
249 Copy data from system memory to MMIO region by using 16-bit access.
251 Copy data from system memory specified by Buffer to MMIO region specified
252 by starting address StartAddress by using 16-bit access. The total number
253 of byte to be copied is specified by Length. Buffer is returned.
255 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
257 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
258 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
260 If Length is not aligned on a 16-bit boundary, then ASSERT().
262 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
264 @param StartAddress The starting address for the MMIO region to be copied to.
265 @param Length The size in bytes of the copy.
266 @param Buffer The pointer to a system memory buffer containing the data to write.
274 IN UINTN StartAddress
,
276 IN CONST UINT16
*Buffer
279 UINT16
*ReturnBuffer
;
281 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
283 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
284 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
286 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
287 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
289 ReturnBuffer
= (UINT16
*) Buffer
;
292 MmioWrite16 (StartAddress
, *(Buffer
++));
294 StartAddress
+= sizeof (UINT16
);
295 Length
-= sizeof (UINT16
);
303 Copy data from system memory to MMIO region by using 32-bit access.
305 Copy data from system memory specified by Buffer to MMIO region specified
306 by starting address StartAddress by using 32-bit access. The total number
307 of byte to be copied is specified by Length. Buffer is returned.
309 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
311 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
312 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
314 If Length is not aligned on a 32-bit boundary, then ASSERT().
316 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
318 @param StartAddress The starting address for the MMIO region to be copied to.
319 @param Length The size in bytes of the copy.
320 @param Buffer The pointer to a system memory buffer containing the data to write.
328 IN UINTN StartAddress
,
330 IN CONST UINT32
*Buffer
333 UINT32
*ReturnBuffer
;
335 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
337 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
338 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
340 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
341 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
343 ReturnBuffer
= (UINT32
*) Buffer
;
346 MmioWrite32 (StartAddress
, *(Buffer
++));
348 StartAddress
+= sizeof (UINT32
);
349 Length
-= sizeof (UINT32
);
356 Copy data from system memory to MMIO region by using 64-bit access.
358 Copy data from system memory specified by Buffer to MMIO region specified
359 by starting address StartAddress by using 64-bit access. The total number
360 of byte to be copied is specified by Length. Buffer is returned.
362 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
364 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
365 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
367 If Length is not aligned on a 64-bit boundary, then ASSERT().
369 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
371 @param StartAddress The starting address for the MMIO region to be copied to.
372 @param Length The size in bytes of the copy.
373 @param Buffer The pointer to a system memory buffer containing the data to write.
381 IN UINTN StartAddress
,
383 IN CONST UINT64
*Buffer
386 UINT64
*ReturnBuffer
;
388 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
390 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
391 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
393 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
394 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
396 ReturnBuffer
= (UINT64
*) Buffer
;
399 MmioWrite64 (StartAddress
, *(Buffer
++));
401 StartAddress
+= sizeof (UINT64
);
402 Length
-= sizeof (UINT64
);