]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiIoLibCpuIo/IoLibMmioBuffer.c
2 I/O Library MMIO Buffer Functions.
3 The implementations are based on EFI_PEI_SERVICE->CpuIo interface.
5 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/IoLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/BaseLib.h>
15 #include <Library/PeiServicesTablePointerLib.h>
18 Copy data from MMIO region to system memory by using 8-bit access.
20 Copy data from MMIO region specified by starting address StartAddress
21 to system memory specified by Buffer by using 8-bit access. The total
22 number of byte to be copied is specified by Length. Buffer is returned.
24 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
25 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
28 @param StartAddress The starting address for the MMIO region to be copied from.
29 @param Length The size, in bytes, of Buffer.
30 @param Buffer The pointer to a system memory buffer receiving the data read.
38 IN UINTN StartAddress
,
45 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
46 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
48 ReturnBuffer
= Buffer
;
50 while (Length
-- != 0) {
51 *(Buffer
++) = MmioRead8 (StartAddress
++);
58 Copy data from MMIO region to system memory by using 16-bit access.
60 Copy data from MMIO region specified by starting address StartAddress
61 to system memory specified by Buffer by using 16-bit access. The total
62 number of byte to be copied is specified by Length. Buffer is returned.
64 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
66 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
67 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
69 If Length is not aligned on a 16-bit boundary, then ASSERT().
70 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
72 @param StartAddress The starting address for the MMIO region to be copied from.
73 @param Length The size, in bytes, of Buffer.
74 @param Buffer The pointer to a system memory buffer receiving the data read.
82 IN UINTN StartAddress
,
89 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
91 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
92 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
94 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
95 ASSERT (((UINTN
)Buffer
& (sizeof (UINT16
) - 1)) == 0);
97 ReturnBuffer
= Buffer
;
100 *(Buffer
++) = MmioRead16 (StartAddress
);
101 StartAddress
+= sizeof (UINT16
);
102 Length
-= sizeof (UINT16
);
109 Copy data from MMIO region to system memory by using 32-bit access.
111 Copy data from MMIO region specified by starting address StartAddress
112 to system memory specified by Buffer by using 32-bit access. The total
113 number of byte to be copied is specified by Length. Buffer is returned.
115 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
117 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
118 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
120 If Length is not aligned on a 32-bit boundary, then ASSERT().
121 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
123 @param StartAddress The starting address for the MMIO region to be copied from.
124 @param Length The size, in bytes, of Buffer.
125 @param Buffer The pointer to a system memory buffer receiving the data read.
133 IN UINTN StartAddress
,
138 UINT32
*ReturnBuffer
;
140 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
142 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
143 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
145 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
146 ASSERT (((UINTN
)Buffer
& (sizeof (UINT32
) - 1)) == 0);
148 ReturnBuffer
= Buffer
;
150 while (Length
!= 0) {
151 *(Buffer
++) = MmioRead32 (StartAddress
);
152 StartAddress
+= sizeof (UINT32
);
153 Length
-= sizeof (UINT32
);
160 Copy data from MMIO region to system memory by using 64-bit access.
162 Copy data from MMIO region specified by starting address StartAddress
163 to system memory specified by Buffer by using 64-bit access. The total
164 number of byte to be copied is specified by Length. Buffer is returned.
166 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
168 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
169 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
171 If Length is not aligned on a 64-bit boundary, then ASSERT().
172 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
174 @param StartAddress The starting address for the MMIO region to be copied from.
175 @param Length The size, in bytes, of Buffer.
176 @param Buffer The pointer to a system memory buffer receiving the data read.
184 IN UINTN StartAddress
,
189 UINT64
*ReturnBuffer
;
191 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
193 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
194 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
196 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
197 ASSERT (((UINTN
)Buffer
& (sizeof (UINT64
) - 1)) == 0);
199 ReturnBuffer
= Buffer
;
201 while (Length
!= 0) {
202 *(Buffer
++) = MmioRead64 (StartAddress
);
203 StartAddress
+= sizeof (UINT64
);
204 Length
-= sizeof (UINT64
);
211 Copy data from system memory to MMIO region by using 8-bit access.
213 Copy data from system memory specified by Buffer to MMIO region specified
214 by starting address StartAddress by using 8-bit access. The total number
215 of byte to be copied is specified by Length. Buffer is returned.
217 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
218 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
221 @param StartAddress The starting address for the MMIO region to be copied to.
222 @param Length The size, in bytes, of Buffer.
223 @param Buffer The pointer to a system memory buffer containing the data to write.
231 IN UINTN StartAddress
,
233 IN CONST UINT8
*Buffer
238 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
239 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
241 ReturnBuffer
= (UINT8
*)Buffer
;
243 while (Length
-- != 0) {
244 MmioWrite8 (StartAddress
++, *(Buffer
++));
251 Copy data from system memory to MMIO region by using 16-bit access.
253 Copy data from system memory specified by Buffer to MMIO region specified
254 by starting address StartAddress by using 16-bit access. The total number
255 of byte to be copied is specified by Length. Buffer is returned.
257 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
259 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
260 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
262 If Length is not aligned on a 16-bit boundary, then ASSERT().
264 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
266 @param StartAddress The starting address for the MMIO region to be copied to.
267 @param Length The size, in bytes, of Buffer.
268 @param Buffer The pointer to a system memory buffer containing the data to write.
276 IN UINTN StartAddress
,
278 IN CONST UINT16
*Buffer
281 UINT16
*ReturnBuffer
;
283 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
285 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
286 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
288 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
289 ASSERT (((UINTN
)Buffer
& (sizeof (UINT16
) - 1)) == 0);
291 ReturnBuffer
= (UINT16
*)Buffer
;
293 while (Length
!= 0) {
294 MmioWrite16 (StartAddress
, *(Buffer
++));
296 StartAddress
+= sizeof (UINT16
);
297 Length
-= sizeof (UINT16
);
304 Copy data from system memory to MMIO region by using 32-bit access.
306 Copy data from system memory specified by Buffer to MMIO region specified
307 by starting address StartAddress by using 32-bit access. The total number
308 of byte to be copied is specified by Length. Buffer is returned.
310 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
312 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
313 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
315 If Length is not aligned on a 32-bit boundary, then ASSERT().
317 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
319 @param StartAddress The starting address for the MMIO region to be copied to.
320 @param Length The size, in bytes, of Buffer.
321 @param Buffer The pointer to a system memory buffer containing the data to write.
329 IN UINTN StartAddress
,
331 IN CONST UINT32
*Buffer
334 UINT32
*ReturnBuffer
;
336 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
338 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
339 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
341 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
342 ASSERT (((UINTN
)Buffer
& (sizeof (UINT32
) - 1)) == 0);
344 ReturnBuffer
= (UINT32
*)Buffer
;
346 while (Length
!= 0) {
347 MmioWrite32 (StartAddress
, *(Buffer
++));
349 StartAddress
+= sizeof (UINT32
);
350 Length
-= sizeof (UINT32
);
357 Copy data from system memory to MMIO region by using 64-bit access.
359 Copy data from system memory specified by Buffer to MMIO region specified
360 by starting address StartAddress by using 64-bit access. The total number
361 of byte to be copied is specified by Length. Buffer is returned.
363 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
365 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
366 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
368 If Length is not aligned on a 64-bit boundary, then ASSERT().
370 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
372 @param StartAddress The starting address for the MMIO region to be copied to.
373 @param Length The size, in bytes, of Buffer.
374 @param Buffer The pointer to a system memory buffer containing the data to write.
382 IN UINTN StartAddress
,
384 IN CONST UINT64
*Buffer
387 UINT64
*ReturnBuffer
;
389 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
391 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
392 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
)Buffer
));
394 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
395 ASSERT (((UINTN
)Buffer
& (sizeof (UINT64
) - 1)) == 0);
397 ReturnBuffer
= (UINT64
*)Buffer
;
399 while (Length
!= 0) {
400 MmioWrite64 (StartAddress
, *(Buffer
++));
402 StartAddress
+= sizeof (UINT64
);
403 Length
-= sizeof (UINT64
);