]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiIoLibCpuIo/IoLibMmioBuffer.c
2 I/O Library MMIO Buffer Functions.
4 Copyright (c) 2007, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/IoLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/BaseLib.h>
21 #include <Library/PeiServicesTablePointerLib.h>
24 Copy data from MMIO region to system memory by using 8-bit access.
26 Copy data from MMIO region specified by starting address StartAddress
27 to system memory specified by Buffer by using 8-bit access. The total
28 number of byte to be copied is specified by Length. Buffer is returned.
30 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
31 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
34 @param StartAddress Starting address for the MMIO region to be copied from.
35 @param Length Size in bytes of the copy.
36 @param Buffer Pointer to a system memory buffer receiving the data read.
44 IN UINTN StartAddress
,
51 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
52 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
54 ReturnBuffer
= Buffer
;
57 *(Buffer
++) = MmioRead8 (StartAddress
++);
64 Copy data from MMIO region to system memory by using 16-bit access.
66 Copy data from MMIO region specified by starting address StartAddress
67 to system memory specified by Buffer by using 16-bit access. The total
68 number of byte to be copied is specified by Length. Buffer is returned.
70 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
72 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
73 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
75 If Length is not aligned on a 16-bit boundary, then ASSERT().
76 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
78 @param StartAddress Starting address for the MMIO region to be copied from.
79 @param Length Size in bytes of the copy.
80 @param Buffer Pointer to a system memory buffer receiving the data read.
88 IN UINTN StartAddress
,
95 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
97 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
98 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
100 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
101 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
103 ReturnBuffer
= Buffer
;
106 *(Buffer
++) = MmioRead16 (StartAddress
);
107 StartAddress
+= sizeof (UINT16
);
108 Length
-= sizeof (UINT16
);
115 Copy data from MMIO region to system memory by using 32-bit access.
117 Copy data from MMIO region specified by starting address StartAddress
118 to system memory specified by Buffer by using 32-bit access. The total
119 number of byte to be copied is specified by Length. Buffer is returned.
121 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
123 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
124 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
126 If Length is not aligned on a 32-bit boundary, then ASSERT().
127 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
129 @param StartAddress Starting address for the MMIO region to be copied from.
130 @param Length Size in bytes of the copy.
131 @param Buffer Pointer to a system memory buffer receiving the data read.
139 IN UINTN StartAddress
,
144 UINT32
*ReturnBuffer
;
146 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
148 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
149 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
151 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
152 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
154 ReturnBuffer
= Buffer
;
157 *(Buffer
++) = MmioRead32 (StartAddress
);
158 StartAddress
+= sizeof (UINT32
);
159 Length
-= sizeof (UINT32
);
166 Copy data from MMIO region to system memory by using 64-bit access.
168 Copy data from MMIO region specified by starting address StartAddress
169 to system memory specified by Buffer by using 64-bit access. The total
170 number of byte to be copied is specified by Length. Buffer is returned.
172 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
174 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
175 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
177 If Length is not aligned on a 64-bit boundary, then ASSERT().
178 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
180 @param StartAddress Starting address for the MMIO region to be copied from.
181 @param Length Size in bytes of the copy.
182 @param Buffer Pointer to a system memory buffer receiving the data read.
190 IN UINTN StartAddress
,
195 UINT64
*ReturnBuffer
;
197 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
199 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
200 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
202 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
203 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
205 ReturnBuffer
= Buffer
;
208 *(Buffer
++) = MmioRead64 (StartAddress
);
209 StartAddress
+= sizeof (UINT64
);
210 Length
-= sizeof (UINT64
);
218 Copy data from system memory to MMIO region by using 8-bit access.
220 Copy data from system memory specified by Buffer to MMIO region specified
221 by starting address StartAddress by using 8-bit access. The total number
222 of byte to be copied is specified by Length. Buffer is returned.
224 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
225 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
228 @param StartAddress Starting address for the MMIO region to be copied to.
229 @param Length Size in bytes of the copy.
230 @param Buffer Pointer to a system memory buffer containing the data to write.
232 @return Size in bytes of the copy.
238 IN UINTN StartAddress
,
240 IN CONST UINT8
*Buffer
245 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
246 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
248 ReturnBuffer
= (UINT8
*) Buffer
;
251 MmioWrite8 (StartAddress
++, *(Buffer
++));
259 Copy data from system memory to MMIO region by using 16-bit access.
261 Copy data from system memory specified by Buffer to MMIO region specified
262 by starting address StartAddress by using 16-bit access. The total number
263 of byte to be copied is specified by Length. Length is returned.
265 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
267 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
268 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
270 If Length is not aligned on a 16-bit boundary, then ASSERT().
272 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
274 @param StartAddress Starting address for the MMIO region to be copied to.
275 @param Length Size in bytes of the copy.
276 @param Buffer Pointer to a system memory buffer containing the data to write.
278 @return Size in bytes of the copy.
284 IN UINTN StartAddress
,
286 IN CONST UINT16
*Buffer
289 UINT16
*ReturnBuffer
;
291 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
293 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
294 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
296 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
297 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
299 ReturnBuffer
= (UINT16
*) Buffer
;
302 MmioWrite16 (StartAddress
, *(Buffer
++));
304 StartAddress
+= sizeof (UINT16
);
305 Length
-= sizeof (UINT16
);
313 Copy data from system memory to MMIO region by using 32-bit access.
315 Copy data from system memory specified by Buffer to MMIO region specified
316 by starting address StartAddress by using 32-bit access. The total number
317 of byte to be copied is specified by Length. Length is returned.
319 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
321 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
322 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
324 If Length is not aligned on a 32-bit boundary, then ASSERT().
326 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
328 @param StartAddress Starting address for the MMIO region to be copied to.
329 @param Length Size in bytes of the copy.
330 @param Buffer Pointer to a system memory buffer containing the data to write.
332 @return Size in bytes of the copy.
338 IN UINTN StartAddress
,
340 IN CONST UINT32
*Buffer
343 UINT32
*ReturnBuffer
;
345 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
347 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
348 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
350 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
351 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
353 ReturnBuffer
= (UINT32
*) Buffer
;
356 MmioWrite32 (StartAddress
, *(Buffer
++));
358 StartAddress
+= sizeof (UINT32
);
359 Length
-= sizeof (UINT32
);
366 Copy data from system memory to MMIO region by using 64-bit access.
368 Copy data from system memory specified by Buffer to MMIO region specified
369 by starting address StartAddress by using 64-bit access. The total number
370 of byte to be copied is specified by Length. Length is returned.
372 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
374 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
375 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
377 If Length is not aligned on a 64-bit boundary, then ASSERT().
379 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
381 @param StartAddress Starting address for the MMIO region to be copied to.
382 @param Length Size in bytes of the copy.
383 @param Buffer Pointer to a system memory buffer containing the data to write.
385 @return Size in bytes of the copy.
391 IN UINTN StartAddress
,
393 IN CONST UINT64
*Buffer
396 UINT64
*ReturnBuffer
;
398 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
400 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
401 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
403 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
404 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
406 ReturnBuffer
= (UINT64
*) Buffer
;
409 MmioWrite64 (StartAddress
, *(Buffer
++));
411 StartAddress
+= sizeof (UINT64
);
412 Length
-= sizeof (UINT64
);