]>
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.
16 // The package level header files this module uses
20 // The Library classes this module consumes
22 #include <Library/IoLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/BaseLib.h>
25 #include <Library/PeiServicesTablePointerLib.h>
28 Copy data from MMIO region to system memory by using 8-bit access.
30 Copy data from MMIO region specified by starting address StartAddress
31 to system memory specified by Buffer by using 8-bit access. The total
32 number of byte to be copied is specified by Length. Buffer is returned.
34 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
35 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
38 @param StartAddress Starting address for the MMIO region to be copied from.
39 @param Length Size in bytes of the copy.
40 @param Buffer Pointer to a system memory buffer receiving the data read.
48 IN UINTN StartAddress
,
55 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
56 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
58 ReturnBuffer
= Buffer
;
61 *(Buffer
++) = MmioRead8 (StartAddress
++);
68 Copy data from MMIO region to system memory by using 16-bit access.
70 Copy data from MMIO region specified by starting address StartAddress
71 to system memory specified by Buffer by using 16-bit access. The total
72 number of byte to be copied is specified by Length. Buffer is returned.
74 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
76 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
77 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
79 If Length is not aligned on a 16-bit boundary, then ASSERT().
80 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
82 @param StartAddress Starting address for the MMIO region to be copied from.
83 @param Length Size in bytes of the copy.
84 @param Buffer Pointer to a system memory buffer receiving the data read.
92 IN UINTN StartAddress
,
99 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
101 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
102 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
104 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
105 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
107 ReturnBuffer
= Buffer
;
110 *(Buffer
++) = MmioRead16 (StartAddress
);
111 StartAddress
+= sizeof (UINT16
);
112 Length
-= sizeof (UINT16
);
119 Copy data from MMIO region to system memory by using 32-bit access.
121 Copy data from MMIO region specified by starting address StartAddress
122 to system memory specified by Buffer by using 32-bit access. The total
123 number of byte to be copied is specified by Length. Buffer is returned.
125 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
127 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
128 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
130 If Length is not aligned on a 32-bit boundary, then ASSERT().
131 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
133 @param StartAddress Starting address for the MMIO region to be copied from.
134 @param Length Size in bytes of the copy.
135 @param Buffer Pointer to a system memory buffer receiving the data read.
143 IN UINTN StartAddress
,
148 UINT32
*ReturnBuffer
;
150 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
152 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
153 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
155 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
156 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
158 ReturnBuffer
= Buffer
;
161 *(Buffer
++) = MmioRead32 (StartAddress
);
162 StartAddress
+= sizeof (UINT32
);
163 Length
-= sizeof (UINT32
);
170 Copy data from MMIO region to system memory by using 64-bit access.
172 Copy data from MMIO region specified by starting address StartAddress
173 to system memory specified by Buffer by using 64-bit access. The total
174 number of byte to be copied is specified by Length. Buffer is returned.
176 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
178 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
179 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
181 If Length is not aligned on a 64-bit boundary, then ASSERT().
182 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
184 @param StartAddress Starting address for the MMIO region to be copied from.
185 @param Length Size in bytes of the copy.
186 @param Buffer Pointer to a system memory buffer receiving the data read.
194 IN UINTN StartAddress
,
199 UINT64
*ReturnBuffer
;
201 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
203 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
204 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
206 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
207 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
209 ReturnBuffer
= Buffer
;
212 *(Buffer
++) = MmioRead64 (StartAddress
);
213 StartAddress
+= sizeof (UINT64
);
214 Length
-= sizeof (UINT64
);
222 Copy data from system memory to MMIO region by using 8-bit access.
224 Copy data from system memory specified by Buffer to MMIO region specified
225 by starting address StartAddress by using 8-bit access. The total number
226 of byte to be copied is specified by Length. Buffer is returned.
228 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
229 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
232 @param StartAddress Starting address for the MMIO region to be copied to.
233 @param Length Size in bytes of the copy.
234 @param Buffer Pointer to a system memory buffer containing the data to write.
236 @return Size in bytes of the copy.
242 IN UINTN StartAddress
,
244 IN CONST UINT8
*Buffer
249 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
250 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
252 ReturnBuffer
= (UINT8
*) Buffer
;
255 MmioWrite8 (StartAddress
++, *(Buffer
++));
263 Copy data from system memory to MMIO region by using 16-bit access.
265 Copy data from system memory specified by Buffer to MMIO region specified
266 by starting address StartAddress by using 16-bit access. The total number
267 of byte to be copied is specified by Length. Length is returned.
269 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
271 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
272 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
274 If Length is not aligned on a 16-bit boundary, then ASSERT().
276 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
278 @param StartAddress Starting address for the MMIO region to be copied to.
279 @param Length Size in bytes of the copy.
280 @param Buffer Pointer to a system memory buffer containing the data to write.
282 @return Size in bytes of the copy.
288 IN UINTN StartAddress
,
290 IN CONST UINT16
*Buffer
293 UINT16
*ReturnBuffer
;
295 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
297 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
298 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
300 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
301 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
303 ReturnBuffer
= (UINT16
*) Buffer
;
306 MmioWrite16 (StartAddress
, *(Buffer
++));
308 StartAddress
+= sizeof (UINT16
);
309 Length
-= sizeof (UINT16
);
317 Copy data from system memory to MMIO region by using 32-bit access.
319 Copy data from system memory specified by Buffer to MMIO region specified
320 by starting address StartAddress by using 32-bit access. The total number
321 of byte to be copied is specified by Length. Length is returned.
323 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
325 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
326 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
328 If Length is not aligned on a 32-bit boundary, then ASSERT().
330 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
332 @param StartAddress Starting address for the MMIO region to be copied to.
333 @param Length Size in bytes of the copy.
334 @param Buffer Pointer to a system memory buffer containing the data to write.
336 @return Size in bytes of the copy.
342 IN UINTN StartAddress
,
344 IN CONST UINT32
*Buffer
347 UINT32
*ReturnBuffer
;
349 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
351 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
352 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
354 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
355 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
357 ReturnBuffer
= (UINT32
*) Buffer
;
360 MmioWrite32 (StartAddress
, *(Buffer
++));
362 StartAddress
+= sizeof (UINT32
);
363 Length
-= sizeof (UINT32
);
370 Copy data from system memory to MMIO region by using 64-bit access.
372 Copy data from system memory specified by Buffer to MMIO region specified
373 by starting address StartAddress by using 64-bit access. The total number
374 of byte to be copied is specified by Length. Length is returned.
376 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
378 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
379 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
381 If Length is not aligned on a 64-bit boundary, then ASSERT().
383 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
385 @param StartAddress Starting address for the MMIO region to be copied to.
386 @param Length Size in bytes of the copy.
387 @param Buffer Pointer to a system memory buffer containing the data to write.
389 @return Size in bytes of the copy.
395 IN UINTN StartAddress
,
397 IN CONST UINT64
*Buffer
400 UINT64
*ReturnBuffer
;
402 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
404 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
405 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
407 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
408 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
410 ReturnBuffer
= (UINT64
*) Buffer
;
413 MmioWrite64 (StartAddress
, *(Buffer
++));
415 StartAddress
+= sizeof (UINT64
);
416 Length
-= sizeof (UINT64
);