]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/SmmIoLibSmmCpuIo2/IoLibMmioBuffer.c
2 I/O Library MMIO Buffer Functions.
4 Copyright (c) 2009 - 2010, 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 "SmmCpuIoLibInternal.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
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
;
247 while (Length
-- > 0) {
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. Buffer 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 The starting address for the MMIO region to be copied to.
272 @param Length The size in bytes of the copy.
273 @param Buffer The pointer to a system memory buffer containing the
282 IN UINTN StartAddress
,
284 IN CONST UINT16
*Buffer
287 UINT16
*ReturnBuffer
;
289 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
291 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
292 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
294 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
295 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
297 ReturnBuffer
= (UINT16
*) Buffer
;
300 MmioWrite16 (StartAddress
, *(Buffer
++));
302 StartAddress
+= sizeof (UINT16
);
303 Length
-= sizeof (UINT16
);
311 Copy data from system memory to MMIO region by using 32-bit access.
313 Copy data from system memory specified by Buffer to MMIO region specified
314 by starting address StartAddress by using 32-bit access. The total number
315 of byte to be copied is specified by Length. Buffer is returned.
317 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
319 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
320 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
322 If Length is not aligned on a 32-bit boundary, then ASSERT().
324 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
326 @param StartAddress The starting address for the MMIO region to be copied to.
327 @param Length The size in bytes of the copy.
328 @param Buffer The pointer to a system memory buffer containing the
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. Buffer 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 The starting address for the MMIO region to be copied to.
381 @param Length The size in bytes of the copy.
382 @param Buffer The pointer to a system memory buffer containing the
391 IN UINTN StartAddress
,
393 IN CONST UINT64
*Buffer
396 UINT64
*ReturnBuffer
;
398 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
400 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
401 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
403 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
404 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
406 ReturnBuffer
= (UINT64
*) Buffer
;
409 MmioWrite64 (StartAddress
, *(Buffer
++));
411 StartAddress
+= sizeof (UINT64
);
412 Length
-= sizeof (UINT64
);