]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeIoLibCpuIo2/IoLibMmioBuffer.c
2 I/O Library MMIO Buffer Functions.
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 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 "DxeCpuIo2LibInternal.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 The starting address for the MMIO region to be copied from.
29 @param Length The size in bytes of the copy.
30 @param Buffer The 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().
71 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
73 @param StartAddress The starting address for the MMIO region to be copied from.
74 @param Length The size in bytes of the copy.
75 @param Buffer The 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 The starting address for the MMIO region to be copied from.
125 @param Length The size in bytes of the copy.
126 @param Buffer The 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().
174 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
176 @param StartAddress The starting address for the MMIO region to be copied from.
177 @param Length The size in bytes of the copy.
178 @param Buffer The pointer to a system memory buffer receiving the data read.
186 IN UINTN StartAddress
,
191 UINT64
*ReturnBuffer
;
193 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
195 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
196 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
198 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
199 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
201 ReturnBuffer
= Buffer
;
204 *(Buffer
++) = MmioRead64 (StartAddress
);
205 StartAddress
+= sizeof (UINT64
);
206 Length
-= sizeof (UINT64
);
214 Copy data from system memory to MMIO region by using 8-bit access.
216 Copy data from system memory specified by Buffer to MMIO region specified
217 by starting address StartAddress by using 8-bit access. The total number
218 of byte to be copied is specified by Length. Buffer is returned.
220 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
221 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
224 @param StartAddress The starting address for the MMIO region to be copied to.
225 @param Length The size in bytes of the copy.
226 @param Buffer The pointer to a system memory buffer containing the data to write.
234 IN UINTN StartAddress
,
236 IN CONST UINT8
*Buffer
241 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
242 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
244 ReturnBuffer
= (UINT8
*) Buffer
;
246 while (Length
-- > 0) {
247 MmioWrite8 (StartAddress
++, *(Buffer
++));
255 Copy data from system memory to MMIO region by using 16-bit access.
257 Copy data from system memory specified by Buffer to MMIO region specified
258 by starting address StartAddress by using 16-bit access. The total number
259 of byte to be copied is specified by Length. Buffer is returned.
261 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
263 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
264 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
266 If Length is not aligned on a 16-bit boundary, then ASSERT().
268 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
270 @param StartAddress The starting address for the MMIO region to be copied to.
271 @param Length The size in bytes of the copy.
272 @param Buffer The pointer to a system memory buffer containing the data to write.
280 IN UINTN StartAddress
,
282 IN CONST UINT16
*Buffer
285 UINT16
*ReturnBuffer
;
287 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
289 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
290 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
292 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
293 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
295 ReturnBuffer
= (UINT16
*) Buffer
;
298 MmioWrite16 (StartAddress
, *(Buffer
++));
300 StartAddress
+= sizeof (UINT16
);
301 Length
-= sizeof (UINT16
);
309 Copy data from system memory to MMIO region by using 32-bit access.
311 Copy data from system memory specified by Buffer to MMIO region specified
312 by starting address StartAddress by using 32-bit access. The total number
313 of byte to be copied is specified by Length. Buffer is returned.
315 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
317 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
318 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
320 If Length is not aligned on a 32-bit boundary, then ASSERT().
322 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
324 @param StartAddress The starting address for the MMIO region to be copied to.
325 @param Length The size in bytes of the copy.
326 @param Buffer The pointer to a system memory buffer containing the data to write.
334 IN UINTN StartAddress
,
336 IN CONST UINT32
*Buffer
339 UINT32
*ReturnBuffer
;
341 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
343 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
344 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
346 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
347 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
349 ReturnBuffer
= (UINT32
*) Buffer
;
352 MmioWrite32 (StartAddress
, *(Buffer
++));
354 StartAddress
+= sizeof (UINT32
);
355 Length
-= sizeof (UINT32
);
362 Copy data from system memory to MMIO region by using 64-bit access.
364 Copy data from system memory specified by Buffer to MMIO region specified
365 by starting address StartAddress by using 64-bit access. The total number
366 of byte to be copied is specified by Length. Buffer is returned.
368 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
370 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
371 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
373 If Length is not aligned on a 64-bit boundary, then ASSERT().
375 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
377 @param StartAddress The starting address for the MMIO region to be copied to.
378 @param Length The size in bytes of the copy.
379 @param Buffer The pointer to a system memory buffer containing the data to write.
387 IN UINTN StartAddress
,
389 IN CONST UINT64
*Buffer
392 UINT64
*ReturnBuffer
;
394 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
396 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
397 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
399 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
400 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
402 ReturnBuffer
= (UINT64
*) Buffer
;
405 MmioWrite64 (StartAddress
, *(Buffer
++));
407 StartAddress
+= sizeof (UINT64
);
408 Length
-= sizeof (UINT64
);