]>
git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/DxeIoLibCpuIo/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.
13 Module Name: IoLibMmioBuffer.c
18 #include "DxeCpuIoLibInternal.h"
21 Copy data from MMIO region to system memory by using 8-bit access.
23 Copy data from MMIO region specified by starting address StartAddress
24 to system memory specified by Buffer by using 8-bit access. The total
25 number of byte to be copied is specified by Length. Buffer is returned.
27 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
28 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
31 @param StartAddress Starting address for the MMIO region to be copied from.
32 @param Length Size in bytes of the copy.
33 @param Buffer Pointer to a system memory buffer receiving the data read.
41 IN UINTN StartAddress
,
48 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
49 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
51 ReturnBuffer
= Buffer
;
53 while (Length
-- > 0) {
54 *(Buffer
++) = MmioRead8 (StartAddress
++);
61 Copy data from MMIO region to system memory by using 16-bit access.
63 Copy data from MMIO region specified by starting address StartAddress
64 to system memory specified by Buffer by using 16-bit access. The total
65 number of byte to be copied is specified by Length. Buffer is returned.
67 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
69 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
70 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
72 If Length is not aligned on a 16-bit boundary, then ASSERT().
74 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
76 @param StartAddress Starting address for the MMIO region to be copied from.
77 @param Length Size in bytes of the copy.
78 @param Buffer Pointer to a system memory buffer receiving the data read.
86 IN UINTN StartAddress
,
93 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
95 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
96 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
98 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
99 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
101 ReturnBuffer
= Buffer
;
104 *(Buffer
++) = MmioRead16 (StartAddress
);
105 StartAddress
+= sizeof (UINT16
);
106 Length
-= sizeof (UINT16
);
113 Copy data from MMIO region to system memory by using 32-bit access.
115 Copy data from MMIO region specified by starting address StartAddress
116 to system memory specified by Buffer by using 32-bit access. The total
117 number of byte to be copied is specified by Length. Buffer is returned.
119 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
121 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
122 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
124 If Length is not aligned on a 32-bit boundary, then ASSERT().
125 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
127 @param StartAddress Starting address for the MMIO region to be copied from.
128 @param Length Size in bytes of the copy.
129 @param Buffer Pointer to a system memory buffer receiving the data read.
137 IN UINTN StartAddress
,
142 UINT32
*ReturnBuffer
;
144 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
146 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
147 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
149 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
150 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
152 ReturnBuffer
= Buffer
;
155 *(Buffer
++) = MmioRead32 (StartAddress
);
156 StartAddress
+= sizeof (UINT32
);
157 Length
-= sizeof (UINT32
);
164 Copy data from MMIO region to system memory by using 64-bit access.
166 Copy data from MMIO region specified by starting address StartAddress
167 to system memory specified by Buffer by using 64-bit access. The total
168 number of byte to be copied is specified by Length. Buffer is returned.
170 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
172 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
173 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
175 If Length is not aligned on a 64-bit boundary, then ASSERT().
177 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
179 @param StartAddress Starting address for the MMIO region to be copied from.
180 @param Length Size in bytes of the copy.
181 @param Buffer Pointer to a system memory buffer receiving the data read.
189 IN UINTN StartAddress
,
194 UINT64
*ReturnBuffer
;
196 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
198 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
199 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
201 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
202 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
204 ReturnBuffer
= Buffer
;
207 *(Buffer
++) = MmioRead64 (StartAddress
);
208 StartAddress
+= sizeof (UINT64
);
209 Length
-= sizeof (UINT64
);
217 Copy data from system memory to MMIO region by using 8-bit access.
219 Copy data from system memory specified by Buffer to MMIO region specified
220 by starting address StartAddress by using 8-bit access. The total number
221 of byte to be copied is specified by Length. Buffer is returned.
223 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
224 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
227 @param StartAddress Starting address for the MMIO region to be copied to.
228 @param Length Size in bytes of the copy.
229 @param Buffer Pointer to a system memory buffer containing the data to write.
231 @return Size in bytes of the copy.
237 IN UINTN StartAddress
,
239 IN CONST UINT8
*Buffer
244 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
245 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
247 ReturnBuffer
= (UINT8
*) Buffer
;
249 while (Length
-- > 0) {
250 MmioWrite8 (StartAddress
++, *(Buffer
++));
258 Copy data from system memory to MMIO region by using 16-bit access.
260 Copy data from system memory specified by Buffer to MMIO region specified
261 by starting address StartAddress by using 16-bit access. The total number
262 of byte to be copied is specified by Length. Length is returned.
264 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
266 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
267 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
269 If Length is not aligned on a 16-bit boundary, then ASSERT().
271 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
273 @param StartAddress Starting address for the MMIO region to be copied to.
274 @param Length Size in bytes of the copy.
275 @param Buffer Pointer to a system memory buffer containing the data to write.
277 @return Size in bytes of the copy.
283 IN UINTN StartAddress
,
285 IN CONST UINT16
*Buffer
288 UINT16
*ReturnBuffer
;
290 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
292 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
293 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
295 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
296 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
298 ReturnBuffer
= (UINT16
*) Buffer
;
301 MmioWrite16 (StartAddress
, *(Buffer
++));
303 StartAddress
+= sizeof (UINT16
);
304 Length
-= sizeof (UINT16
);
312 Copy data from system memory to MMIO region by using 32-bit access.
314 Copy data from system memory specified by Buffer to MMIO region specified
315 by starting address StartAddress by using 32-bit access. The total number
316 of byte to be copied is specified by Length. Length is returned.
318 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
320 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
321 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
323 If Length is not aligned on a 32-bit boundary, then ASSERT().
325 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
327 @param StartAddress Starting address for the MMIO region to be copied to.
328 @param Length Size in bytes of the copy.
329 @param Buffer Pointer to a system memory buffer containing the data to write.
331 @return Size in bytes of the copy.
337 IN UINTN StartAddress
,
339 IN CONST UINT32
*Buffer
342 UINT32
*ReturnBuffer
;
344 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
346 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
347 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
349 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
350 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
352 ReturnBuffer
= (UINT32
*) Buffer
;
355 MmioWrite32 (StartAddress
, *(Buffer
++));
357 StartAddress
+= sizeof (UINT32
);
358 Length
-= sizeof (UINT32
);
365 Copy data from system memory to MMIO region by using 64-bit access.
367 Copy data from system memory specified by Buffer to MMIO region specified
368 by starting address StartAddress by using 64-bit access. The total number
369 of byte to be copied is specified by Length. Length is returned.
371 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
373 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
374 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
376 If Length is not aligned on a 64-bit boundary, then ASSERT().
378 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
380 @param StartAddress Starting address for the MMIO region to be copied to.
381 @param Length Size in bytes of the copy.
382 @param Buffer Pointer to a system memory buffer containing the data to write.
384 @return Size in bytes of the copy.
390 IN UINTN StartAddress
,
392 IN CONST UINT64
*Buffer
395 UINT64
*ReturnBuffer
;
397 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
399 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
400 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
402 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
403 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
405 ReturnBuffer
= (UINT64
*) Buffer
;
408 MmioWrite64 (StartAddress
, *(Buffer
++));
410 StartAddress
+= sizeof (UINT64
);
411 Length
-= sizeof (UINT64
);