]>
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 - 2009, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <Library/IoLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/BaseLib.h>
22 #include <Library/PeiServicesTablePointerLib.h>
25 Copy data from MMIO region to system memory by using 8-bit access.
27 Copy data from MMIO region specified by starting address StartAddress
28 to system memory specified by Buffer by using 8-bit access. The total
29 number of byte to be copied is specified by Length. Buffer is returned.
31 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
32 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
35 @param StartAddress The starting address for the MMIO region to be copied from.
36 @param Length The size, in bytes, of Buffer.
37 @param Buffer The pointer to a system memory buffer receiving the data read.
45 IN UINTN StartAddress
,
52 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
53 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
55 ReturnBuffer
= Buffer
;
57 while (Length
-- != 0) {
58 *(Buffer
++) = MmioRead8 (StartAddress
++);
65 Copy data from MMIO region to system memory by using 16-bit access.
67 Copy data from MMIO region specified by starting address StartAddress
68 to system memory specified by Buffer by using 16-bit access. The total
69 number of byte to be copied is specified by Length. Buffer is returned.
71 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
73 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
74 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
76 If Length is not aligned on a 16-bit boundary, then ASSERT().
77 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
79 @param StartAddress The starting address for the MMIO region to be copied from.
80 @param Length The size, in bytes, of Buffer.
81 @param Buffer The pointer to a system memory buffer receiving the data read.
89 IN UINTN StartAddress
,
96 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
98 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
99 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
101 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
102 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
104 ReturnBuffer
= Buffer
;
106 while (Length
!= 0) {
107 *(Buffer
++) = MmioRead16 (StartAddress
);
108 StartAddress
+= sizeof (UINT16
);
109 Length
-= sizeof (UINT16
);
116 Copy data from MMIO region to system memory by using 32-bit access.
118 Copy data from MMIO region specified by starting address StartAddress
119 to system memory specified by Buffer by using 32-bit access. The total
120 number of byte to be copied is specified by Length. Buffer is returned.
122 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
124 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
125 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
127 If Length is not aligned on a 32-bit boundary, then ASSERT().
128 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
130 @param StartAddress The starting address for the MMIO region to be copied from.
131 @param Length The size, in bytes, of Buffer.
132 @param Buffer The pointer to a system memory buffer receiving the data read.
140 IN UINTN StartAddress
,
145 UINT32
*ReturnBuffer
;
147 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
149 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
150 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
152 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
153 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
155 ReturnBuffer
= Buffer
;
157 while (Length
!= 0) {
158 *(Buffer
++) = MmioRead32 (StartAddress
);
159 StartAddress
+= sizeof (UINT32
);
160 Length
-= sizeof (UINT32
);
167 Copy data from MMIO region to system memory by using 64-bit access.
169 Copy data from MMIO region specified by starting address StartAddress
170 to system memory specified by Buffer by using 64-bit access. The total
171 number of byte to be copied is specified by Length. Buffer is returned.
173 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
175 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
176 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
178 If Length is not aligned on a 64-bit boundary, then ASSERT().
179 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
181 @param StartAddress The starting address for the MMIO region to be copied from.
182 @param Length The size, in bytes, of Buffer.
183 @param Buffer The pointer to a system memory buffer receiving the data read.
191 IN UINTN StartAddress
,
196 UINT64
*ReturnBuffer
;
198 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
200 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
201 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
203 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
204 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
206 ReturnBuffer
= Buffer
;
208 while (Length
!= 0) {
209 *(Buffer
++) = MmioRead64 (StartAddress
);
210 StartAddress
+= sizeof (UINT64
);
211 Length
-= sizeof (UINT64
);
219 Copy data from system memory to MMIO region by using 8-bit access.
221 Copy data from system memory specified by Buffer to MMIO region specified
222 by starting address StartAddress by using 8-bit access. The total number
223 of byte to be copied is specified by Length. Buffer is returned.
225 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
226 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
229 @param StartAddress The starting address for the MMIO region to be copied to.
230 @param Length The size, in bytes, of Buffer.
231 @param Buffer The pointer to a system memory buffer containing the data to write.
239 IN UINTN StartAddress
,
241 IN CONST UINT8
*Buffer
246 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
247 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
249 ReturnBuffer
= (UINT8
*) Buffer
;
251 while (Length
-- != 0) {
252 MmioWrite8 (StartAddress
++, *(Buffer
++));
260 Copy data from system memory to MMIO region by using 16-bit access.
262 Copy data from system memory specified by Buffer to MMIO region specified
263 by starting address StartAddress by using 16-bit access. The total number
264 of byte to be copied is specified by Length. Buffer is returned.
266 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
268 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
269 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
271 If Length is not aligned on a 16-bit boundary, then ASSERT().
273 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
275 @param StartAddress The starting address for the MMIO region to be copied to.
276 @param Length The size, in bytes, of Buffer.
277 @param Buffer The pointer to a system memory buffer containing the data to write.
285 IN UINTN StartAddress
,
287 IN CONST UINT16
*Buffer
290 UINT16
*ReturnBuffer
;
292 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
294 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
295 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
297 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
298 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
300 ReturnBuffer
= (UINT16
*) Buffer
;
302 while (Length
!= 0) {
303 MmioWrite16 (StartAddress
, *(Buffer
++));
305 StartAddress
+= sizeof (UINT16
);
306 Length
-= sizeof (UINT16
);
314 Copy data from system memory to MMIO region by using 32-bit access.
316 Copy data from system memory specified by Buffer to MMIO region specified
317 by starting address StartAddress by using 32-bit access. The total number
318 of byte to be copied is specified by Length. Buffer is returned.
320 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
322 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
323 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
325 If Length is not aligned on a 32-bit boundary, then ASSERT().
327 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
329 @param StartAddress The starting address for the MMIO region to be copied to.
330 @param Length The size, in bytes, of Buffer.
331 @param Buffer The pointer to a system memory buffer containing the data to write.
339 IN UINTN StartAddress
,
341 IN CONST UINT32
*Buffer
344 UINT32
*ReturnBuffer
;
346 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
348 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
349 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
351 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
352 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
354 ReturnBuffer
= (UINT32
*) Buffer
;
356 while (Length
!= 0) {
357 MmioWrite32 (StartAddress
, *(Buffer
++));
359 StartAddress
+= sizeof (UINT32
);
360 Length
-= sizeof (UINT32
);
367 Copy data from system memory to MMIO region by using 64-bit access.
369 Copy data from system memory specified by Buffer to MMIO region specified
370 by starting address StartAddress by using 64-bit access. The total number
371 of byte to be copied is specified by Length. Buffer is returned.
373 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
375 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
376 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
378 If Length is not aligned on a 64-bit boundary, then ASSERT().
380 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
382 @param StartAddress The starting address for the MMIO region to be copied to.
383 @param Length The size, in bytes, of Buffer.
384 @param Buffer The pointer to a system memory buffer containing the data to write.
392 IN UINTN StartAddress
,
394 IN CONST UINT64
*Buffer
397 UINT64
*ReturnBuffer
;
399 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
401 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
402 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
404 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
405 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
407 ReturnBuffer
= (UINT64
*) Buffer
;
409 while (Length
!= 0) {
410 MmioWrite64 (StartAddress
, *(Buffer
++));
412 StartAddress
+= sizeof (UINT64
);
413 Length
-= sizeof (UINT64
);