]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeIoLibEsal/IoLibMmioBuffer.c
2 I/O Library MMIO Buffer Functions.
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 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.
15 #include "DxeIoLibEsalInternal.h"
18 Copy data from MMIO region to system memory by using 8-bit access.
20 Copy data from MMIO region specified by starting address StartAddress
21 to system memory specified by Buffer by using 8-bit access. The total
22 number of byte to be copied is specified by Length. Buffer is returned.
24 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
25 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
28 @param StartAddress Starting address for the MMIO region to be copied from.
29 @param Length Size in bytes of the copy.
30 @param Buffer Pointer to a system memory buffer receiving the data read.
38 IN UINTN StartAddress
,
45 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
46 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
48 ReturnBuffer
= Buffer
;
50 while (Length
-- > 0) {
51 *(Buffer
++) = MmioRead8 (StartAddress
++);
58 Copy data from MMIO region to system memory by using 16-bit access.
60 Copy data from MMIO region specified by starting address StartAddress
61 to system memory specified by Buffer by using 16-bit access. The total
62 number of byte to be copied is specified by Length. Buffer is returned.
64 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
66 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
67 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
69 If Length is not aligned on a 16-bit boundary, then ASSERT().
70 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
72 @param StartAddress Starting address for the MMIO region to be copied from.
73 @param Length Size in bytes of the copy.
74 @param Buffer Pointer to a system memory buffer receiving the data read.
82 IN UINTN StartAddress
,
89 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
91 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
92 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
94 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
95 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
97 ReturnBuffer
= Buffer
;
100 *(Buffer
++) = MmioRead16 (StartAddress
);
101 StartAddress
+= sizeof (UINT16
);
102 Length
-= sizeof (UINT16
);
109 Copy data from MMIO region to system memory by using 32-bit access.
111 Copy data from MMIO region specified by starting address StartAddress
112 to system memory specified by Buffer by using 32-bit access. The total
113 number of byte to be copied is specified by Length. Buffer is returned.
115 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
117 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
118 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
120 If Length is not aligned on a 32-bit boundary, then ASSERT().
121 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
123 @param StartAddress Starting address for the MMIO region to be copied from.
124 @param Length Size in bytes of the copy.
125 @param Buffer Pointer to a system memory buffer receiving the data read.
133 IN UINTN StartAddress
,
138 UINT32
*ReturnBuffer
;
140 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
142 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
143 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
145 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
146 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
148 ReturnBuffer
= Buffer
;
151 *(Buffer
++) = MmioRead32 (StartAddress
);
152 StartAddress
+= sizeof (UINT32
);
153 Length
-= sizeof (UINT32
);
160 Copy data from MMIO region to system memory by using 64-bit access.
162 Copy data from MMIO region specified by starting address StartAddress
163 to system memory specified by Buffer by using 64-bit access. The total
164 number of byte to be copied is specified by Length. Buffer is returned.
166 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
168 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
169 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
171 If Length is not aligned on a 64-bit boundary, then ASSERT().
172 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
174 @param StartAddress Starting address for the MMIO region to be copied from.
175 @param Length Size in bytes of the copy.
176 @param Buffer Pointer to a system memory buffer receiving the data read.
184 IN UINTN StartAddress
,
189 UINT64
*ReturnBuffer
;
191 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
193 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
194 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
196 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
197 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
199 ReturnBuffer
= Buffer
;
202 *(Buffer
++) = MmioRead64 (StartAddress
);
203 StartAddress
+= sizeof (UINT64
);
204 Length
-= sizeof (UINT64
);
212 Copy data from system memory to MMIO region by using 8-bit access.
214 Copy data from system memory specified by Buffer to MMIO region specified
215 by starting address StartAddress by using 8-bit access. The total number
216 of byte to be copied is specified by Length. Buffer is returned.
218 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
219 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
222 @param StartAddress Starting address for the MMIO region to be copied to.
223 @param Length Size in bytes of the copy.
224 @param Buffer Pointer to a system memory buffer containing the data to write.
232 IN UINTN StartAddress
,
234 IN CONST UINT8
*Buffer
239 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
240 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
242 ReturnBuffer
= (UINT8
*) Buffer
;
244 while (Length
-- > 0) {
245 MmioWrite8 (StartAddress
++, *(Buffer
++));
253 Copy data from system memory to MMIO region by using 16-bit access.
255 Copy data from system memory specified by Buffer to MMIO region specified
256 by starting address StartAddress by using 16-bit access. The total number
257 of byte to be copied is specified by Length. Buffer is returned.
259 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
261 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
262 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
264 If Length is not aligned on a 16-bit boundary, then ASSERT().
266 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
268 @param StartAddress Starting address for the MMIO region to be copied to.
269 @param Length Size in bytes of the copy.
270 @param Buffer Pointer to a system memory buffer containing the data to write.
278 IN UINTN StartAddress
,
280 IN CONST UINT16
*Buffer
283 UINT16
*ReturnBuffer
;
285 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
287 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
288 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
290 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
291 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
293 ReturnBuffer
= (UINT16
*) Buffer
;
296 MmioWrite16 (StartAddress
, *(Buffer
++));
298 StartAddress
+= sizeof (UINT16
);
299 Length
-= sizeof (UINT16
);
307 Copy data from system memory to MMIO region by using 32-bit access.
309 Copy data from system memory specified by Buffer to MMIO region specified
310 by starting address StartAddress by using 32-bit access. The total number
311 of byte to be copied is specified by Length. Buffer is returned.
313 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
315 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
316 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
318 If Length is not aligned on a 32-bit boundary, then ASSERT().
320 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
322 @param StartAddress Starting address for the MMIO region to be copied to.
323 @param Length Size in bytes of the copy.
324 @param Buffer Pointer to a system memory buffer containing the data to write.
332 IN UINTN StartAddress
,
334 IN CONST UINT32
*Buffer
337 UINT32
*ReturnBuffer
;
339 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
341 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
342 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
344 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
345 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
347 ReturnBuffer
= (UINT32
*) Buffer
;
350 MmioWrite32 (StartAddress
, *(Buffer
++));
352 StartAddress
+= sizeof (UINT32
);
353 Length
-= sizeof (UINT32
);
360 Copy data from system memory to MMIO region by using 64-bit access.
362 Copy data from system memory specified by Buffer to MMIO region specified
363 by starting address StartAddress by using 64-bit access. The total number
364 of byte to be copied is specified by Length. Buffer is returned.
366 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
368 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
369 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
371 If Length is not aligned on a 64-bit boundary, then ASSERT().
373 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
375 @param StartAddress Starting address for the MMIO region to be copied to.
376 @param Length Size in bytes of the copy.
377 @param Buffer Pointer to a system memory buffer containing the data to write.
385 IN UINTN StartAddress
,
387 IN CONST UINT64
*Buffer
390 UINT64
*ReturnBuffer
;
392 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
394 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
395 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
397 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
398 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
400 ReturnBuffer
= (UINT64
*) Buffer
;
403 MmioWrite64 (StartAddress
, *(Buffer
++));
405 StartAddress
+= sizeof (UINT64
);
406 Length
-= sizeof (UINT64
);