]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/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 common header file for this module.
18 #include "CommonHeader.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
;
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().
73 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
75 @param StartAddress Starting address for the MMIO region to be copied from.
76 @param Length Size in bytes of the copy.
77 @param Buffer Pointer to a system memory buffer receiving the data read.
85 IN UINTN StartAddress
,
92 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
94 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
95 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
97 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
98 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
100 ReturnBuffer
= Buffer
;
103 *(Buffer
++) = MmioRead16 (StartAddress
);
104 StartAddress
+= sizeof (UINT16
);
105 Length
-= sizeof (UINT16
);
112 Copy data from MMIO region to system memory by using 32-bit access.
114 Copy data from MMIO region specified by starting address StartAddress
115 to system memory specified by Buffer by using 32-bit access. The total
116 number of byte to be copied is specified by Length. Buffer is returned.
118 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
120 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
121 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
123 If Length is not aligned on a 32-bit boundary, then ASSERT().
124 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
126 @param StartAddress Starting address for the MMIO region to be copied from.
127 @param Length Size in bytes of the copy.
128 @param Buffer Pointer to a system memory buffer receiving the data read.
136 IN UINTN StartAddress
,
141 UINT32
*ReturnBuffer
;
143 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
145 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
146 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
148 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
149 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
151 ReturnBuffer
= Buffer
;
154 *(Buffer
++) = MmioRead32 (StartAddress
);
155 StartAddress
+= sizeof (UINT32
);
156 Length
-= sizeof (UINT32
);
163 Copy data from MMIO region to system memory by using 64-bit access.
165 Copy data from MMIO region specified by starting address StartAddress
166 to system memory specified by Buffer by using 64-bit access. The total
167 number of byte to be copied is specified by Length. Buffer is returned.
169 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
171 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
172 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
174 If Length is not aligned on a 64-bit boundary, then ASSERT().
175 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
177 @param StartAddress Starting address for the MMIO region to be copied from.
178 @param Length Size in bytes of the copy.
179 @param Buffer Pointer to a system memory buffer receiving the data read.
187 IN UINTN StartAddress
,
192 UINT64
*ReturnBuffer
;
194 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
196 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
197 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
199 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
200 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
202 ReturnBuffer
= Buffer
;
205 *(Buffer
++) = MmioRead64 (StartAddress
);
206 StartAddress
+= sizeof (UINT64
);
207 Length
-= sizeof (UINT64
);
215 Copy data from system memory to MMIO region by using 8-bit access.
217 Copy data from system memory specified by Buffer to MMIO region specified
218 by starting address StartAddress by using 8-bit access. The total number
219 of byte to be copied is specified by Length. Buffer is returned.
221 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
222 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
225 @param StartAddress Starting address for the MMIO region to be copied to.
226 @param Length Size in bytes of the copy.
227 @param Buffer Pointer to a system memory buffer containing the data to write.
229 @return Size in bytes of the copy.
235 IN UINTN StartAddress
,
237 IN CONST UINT8
*Buffer
242 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
243 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
245 ReturnBuffer
= (UINT8
*) Buffer
;
248 MmioWrite8 (StartAddress
++, *(Buffer
++));
256 Copy data from system memory to MMIO region by using 16-bit access.
258 Copy data from system memory specified by Buffer to MMIO region specified
259 by starting address StartAddress by using 16-bit access. The total number
260 of byte to be copied is specified by Length. Length is returned.
262 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
264 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
265 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
267 If Length is not aligned on a 16-bit boundary, then ASSERT().
269 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
271 @param StartAddress Starting address for the MMIO region to be copied to.
272 @param Length Size in bytes of the copy.
273 @param Buffer Pointer to a system memory buffer containing the data to write.
275 @return Size in bytes of the copy.
281 IN UINTN StartAddress
,
283 IN CONST UINT16
*Buffer
286 UINT16
*ReturnBuffer
;
288 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
290 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
291 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
293 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
294 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
296 ReturnBuffer
= (UINT16
*) Buffer
;
299 MmioWrite16 (StartAddress
, *(Buffer
++));
301 StartAddress
+= sizeof (UINT16
);
302 Length
-= sizeof (UINT16
);
310 Copy data from system memory to MMIO region by using 32-bit access.
312 Copy data from system memory specified by Buffer to MMIO region specified
313 by starting address StartAddress by using 32-bit access. The total number
314 of byte to be copied is specified by Length. Length is returned.
316 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
318 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
319 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
321 If Length is not aligned on a 32-bit boundary, then ASSERT().
323 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
325 @param StartAddress Starting address for the MMIO region to be copied to.
326 @param Length Size in bytes of the copy.
327 @param Buffer Pointer to a system memory buffer containing the data to write.
329 @return Size in bytes of the copy.
335 IN UINTN StartAddress
,
337 IN CONST UINT32
*Buffer
340 UINT32
*ReturnBuffer
;
342 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
344 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
345 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
347 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
348 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
350 ReturnBuffer
= (UINT32
*) Buffer
;
353 MmioWrite32 (StartAddress
, *(Buffer
++));
355 StartAddress
+= sizeof (UINT32
);
356 Length
-= sizeof (UINT32
);
363 Copy data from system memory to MMIO region by using 64-bit access.
365 Copy data from system memory specified by Buffer to MMIO region specified
366 by starting address StartAddress by using 64-bit access. The total number
367 of byte to be copied is specified by Length. Length is returned.
369 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
371 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
372 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
374 If Length is not aligned on a 64-bit boundary, then ASSERT().
376 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
378 @param StartAddress Starting address for the MMIO region to be copied to.
379 @param Length Size in bytes of the copy.
380 @param Buffer Pointer to a system memory buffer containing the data to write.
382 @return Size in bytes of the copy.
388 IN UINTN StartAddress
,
390 IN CONST UINT64
*Buffer
393 UINT64
*ReturnBuffer
;
395 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
397 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
398 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
400 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
401 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
403 ReturnBuffer
= (UINT64
*) Buffer
;
406 MmioWrite64 (StartAddress
, *(Buffer
++));
408 StartAddress
+= sizeof (UINT64
);
409 Length
-= sizeof (UINT64
);