]>
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.
16 #include "DxeCpuIoLibInternal.h"
19 Copy data from MMIO region to system memory by using 8-bit access.
21 Copy data from MMIO region specified by starting address StartAddress
22 to system memory specified by Buffer by using 8-bit access. The total
23 number of byte to be copied is specified by Length. Buffer is returned.
25 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
26 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
29 @param StartAddress Starting address for the MMIO region to be copied from.
30 @param Length Size in bytes of the copy.
31 @param Buffer Pointer to a system memory buffer receiving the data read.
39 IN UINTN StartAddress
,
46 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
47 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
49 ReturnBuffer
= Buffer
;
51 while (Length
-- > 0) {
52 *(Buffer
++) = MmioRead8 (StartAddress
++);
59 Copy data from MMIO region to system memory by using 16-bit access.
61 Copy data from MMIO region specified by starting address StartAddress
62 to system memory specified by Buffer by using 16-bit access. The total
63 number of byte to be copied is specified by Length. Buffer is returned.
65 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
67 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
68 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
70 If Length is not aligned on a 16-bit boundary, then ASSERT().
71 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
73 @param StartAddress Starting address for the MMIO region to be copied from.
74 @param Length Size in bytes of the copy.
75 @param Buffer Pointer to a system memory buffer receiving the data read.
83 IN UINTN StartAddress
,
90 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
92 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
93 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
95 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
96 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
98 ReturnBuffer
= Buffer
;
101 *(Buffer
++) = MmioRead16 (StartAddress
);
102 StartAddress
+= sizeof (UINT16
);
103 Length
-= sizeof (UINT16
);
110 Copy data from MMIO region to system memory by using 32-bit access.
112 Copy data from MMIO region specified by starting address StartAddress
113 to system memory specified by Buffer by using 32-bit access. The total
114 number of byte to be copied is specified by Length. Buffer is returned.
116 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
118 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
119 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
121 If Length is not aligned on a 32-bit boundary, then ASSERT().
122 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
124 @param StartAddress Starting address for the MMIO region to be copied from.
125 @param Length Size in bytes of the copy.
126 @param Buffer Pointer to a system memory buffer receiving the data read.
134 IN UINTN StartAddress
,
139 UINT32
*ReturnBuffer
;
141 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
143 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
144 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
146 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
147 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
149 ReturnBuffer
= Buffer
;
152 *(Buffer
++) = MmioRead32 (StartAddress
);
153 StartAddress
+= sizeof (UINT32
);
154 Length
-= sizeof (UINT32
);
161 Copy data from MMIO region to system memory by using 64-bit access.
163 Copy data from MMIO region specified by starting address StartAddress
164 to system memory specified by Buffer by using 64-bit access. The total
165 number of byte to be copied is specified by Length. Buffer is returned.
167 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
169 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
170 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
172 If Length is not aligned on a 64-bit boundary, then ASSERT().
173 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
175 @param StartAddress Starting address for the MMIO region to be copied from.
176 @param Length Size in bytes of the copy.
177 @param Buffer Pointer to a system memory buffer receiving the data read.
185 IN UINTN StartAddress
,
190 UINT64
*ReturnBuffer
;
192 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
194 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
195 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
197 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
198 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
200 ReturnBuffer
= Buffer
;
203 *(Buffer
++) = MmioRead64 (StartAddress
);
204 StartAddress
+= sizeof (UINT64
);
205 Length
-= sizeof (UINT64
);
213 Copy data from system memory to MMIO region by using 8-bit access.
215 Copy data from system memory specified by Buffer to MMIO region specified
216 by starting address StartAddress by using 8-bit access. The total number
217 of byte to be copied is specified by Length. Buffer is returned.
219 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
220 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
223 @param StartAddress Starting address for the MMIO region to be copied to.
224 @param Length Size in bytes of the copy.
225 @param Buffer Pointer to a system memory buffer containing the data to write.
227 @return Size in bytes of the copy.
233 IN UINTN StartAddress
,
235 IN CONST UINT8
*Buffer
240 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
241 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
243 ReturnBuffer
= (UINT8
*) Buffer
;
245 while (Length
-- > 0) {
246 MmioWrite8 (StartAddress
++, *(Buffer
++));
254 Copy data from system memory to MMIO region by using 16-bit access.
256 Copy data from system memory specified by Buffer to MMIO region specified
257 by starting address StartAddress by using 16-bit access. The total number
258 of byte to be copied is specified by Length. Length is returned.
260 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
262 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
263 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
265 If Length is not aligned on a 16-bit boundary, then ASSERT().
267 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
269 @param StartAddress Starting address for the MMIO region to be copied to.
270 @param Length Size in bytes of the copy.
271 @param Buffer Pointer to a system memory buffer containing the data to write.
273 @return Size in bytes of the copy.
279 IN UINTN StartAddress
,
281 IN CONST UINT16
*Buffer
284 UINT16
*ReturnBuffer
;
286 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
288 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
289 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
291 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
292 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
294 ReturnBuffer
= (UINT16
*) Buffer
;
297 MmioWrite16 (StartAddress
, *(Buffer
++));
299 StartAddress
+= sizeof (UINT16
);
300 Length
-= sizeof (UINT16
);
308 Copy data from system memory to MMIO region by using 32-bit access.
310 Copy data from system memory specified by Buffer to MMIO region specified
311 by starting address StartAddress by using 32-bit access. The total number
312 of byte to be copied is specified by Length. Length is returned.
314 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
316 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
317 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
319 If Length is not aligned on a 32-bit boundary, then ASSERT().
321 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
323 @param StartAddress Starting address for the MMIO region to be copied to.
324 @param Length Size in bytes of the copy.
325 @param Buffer Pointer to a system memory buffer containing the data to write.
327 @return Size in bytes of the copy.
333 IN UINTN StartAddress
,
335 IN CONST UINT32
*Buffer
338 UINT32
*ReturnBuffer
;
340 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
342 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
343 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
345 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
346 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
348 ReturnBuffer
= (UINT32
*) Buffer
;
351 MmioWrite32 (StartAddress
, *(Buffer
++));
353 StartAddress
+= sizeof (UINT32
);
354 Length
-= sizeof (UINT32
);
361 Copy data from system memory to MMIO region by using 64-bit access.
363 Copy data from system memory specified by Buffer to MMIO region specified
364 by starting address StartAddress by using 64-bit access. The total number
365 of byte to be copied is specified by Length. Length is returned.
367 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
369 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
370 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
372 If Length is not aligned on a 64-bit boundary, then ASSERT().
374 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
376 @param StartAddress Starting address for the MMIO region to be copied to.
377 @param Length Size in bytes of the copy.
378 @param Buffer Pointer to a system memory buffer containing the data to write.
380 @return Size in bytes of the copy.
386 IN UINTN StartAddress
,
388 IN CONST UINT64
*Buffer
391 UINT64
*ReturnBuffer
;
393 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
395 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
396 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
398 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
399 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
401 ReturnBuffer
= (UINT64
*) Buffer
;
404 MmioWrite64 (StartAddress
, *(Buffer
++));
406 StartAddress
+= sizeof (UINT64
);
407 Length
-= sizeof (UINT64
);