]>
git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/DxeIoLibCpuIo/IoLibMmioBuffer.c
2 I/O Library MMIO Buffer Functions.
4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
7 Module Name: IoLibMmioBuffer.c
12 #include "DxeCpuIoLibInternal.h"
15 Copy data from MMIO region to system memory by using 8-bit access.
17 Copy data from MMIO region specified by starting address StartAddress
18 to system memory specified by Buffer by using 8-bit access. The total
19 number of byte to be copied is specified by Length. Buffer is returned.
21 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
22 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
25 @param StartAddress Starting address for the MMIO region to be copied from.
26 @param Length Size in bytes of the copy.
27 @param Buffer Pointer to a system memory buffer receiving the data read.
35 IN UINTN StartAddress
,
42 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
43 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
45 ReturnBuffer
= Buffer
;
47 while (Length
-- > 0) {
48 *(Buffer
++) = MmioRead8 (StartAddress
++);
55 Copy data from MMIO region to system memory by using 16-bit access.
57 Copy data from MMIO region specified by starting address StartAddress
58 to system memory specified by Buffer by using 16-bit access. The total
59 number of byte to be copied is specified by Length. Buffer is returned.
61 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
63 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
64 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
66 If Length is not aligned on a 16-bit boundary, then ASSERT().
68 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
70 @param StartAddress Starting address for the MMIO region to be copied from.
71 @param Length Size in bytes of the copy.
72 @param Buffer Pointer to a system memory buffer receiving the data read.
80 IN UINTN StartAddress
,
87 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
89 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
90 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
92 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
93 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
95 ReturnBuffer
= Buffer
;
98 *(Buffer
++) = MmioRead16 (StartAddress
);
99 StartAddress
+= sizeof (UINT16
);
100 Length
-= sizeof (UINT16
);
107 Copy data from MMIO region to system memory by using 32-bit access.
109 Copy data from MMIO region specified by starting address StartAddress
110 to system memory specified by Buffer by using 32-bit access. The total
111 number of byte to be copied is specified by Length. Buffer is returned.
113 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
115 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
116 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
118 If Length is not aligned on a 32-bit boundary, then ASSERT().
119 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
121 @param StartAddress Starting address for the MMIO region to be copied from.
122 @param Length Size in bytes of the copy.
123 @param Buffer Pointer to a system memory buffer receiving the data read.
131 IN UINTN StartAddress
,
136 UINT32
*ReturnBuffer
;
138 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
140 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
141 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
143 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
144 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
146 ReturnBuffer
= Buffer
;
149 *(Buffer
++) = MmioRead32 (StartAddress
);
150 StartAddress
+= sizeof (UINT32
);
151 Length
-= sizeof (UINT32
);
158 Copy data from MMIO region to system memory by using 64-bit access.
160 Copy data from MMIO region specified by starting address StartAddress
161 to system memory specified by Buffer by using 64-bit access. The total
162 number of byte to be copied is specified by Length. Buffer is returned.
164 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
166 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
167 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
169 If Length is not aligned on a 64-bit boundary, then ASSERT().
171 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
173 @param StartAddress Starting address for the MMIO region to be copied from.
174 @param Length Size in bytes of the copy.
175 @param Buffer Pointer to a system memory buffer receiving the data read.
183 IN UINTN StartAddress
,
188 UINT64
*ReturnBuffer
;
190 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
192 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
193 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
195 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
196 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
198 ReturnBuffer
= Buffer
;
201 *(Buffer
++) = MmioRead64 (StartAddress
);
202 StartAddress
+= sizeof (UINT64
);
203 Length
-= sizeof (UINT64
);
211 Copy data from system memory to MMIO region by using 8-bit access.
213 Copy data from system memory specified by Buffer to MMIO region specified
214 by starting address StartAddress by using 8-bit access. The total number
215 of byte to be copied is specified by Length. Buffer is returned.
217 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
218 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
221 @param StartAddress Starting address for the MMIO region to be copied to.
222 @param Length Size in bytes of the copy.
223 @param Buffer Pointer to a system memory buffer containing the data to write.
231 IN UINTN StartAddress
,
233 IN CONST UINT8
*Buffer
238 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
239 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
241 ReturnBuffer
= (UINT8
*) Buffer
;
243 while (Length
-- > 0) {
244 MmioWrite8 (StartAddress
++, *(Buffer
++));
252 Copy data from system memory to MMIO region by using 16-bit access.
254 Copy data from system memory specified by Buffer to MMIO region specified
255 by starting address StartAddress by using 16-bit access. The total number
256 of byte to be copied is specified by Length. Buffer is returned.
258 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
260 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
261 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
263 If Length is not aligned on a 16-bit boundary, then ASSERT().
265 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
267 @param StartAddress Starting address for the MMIO region to be copied to.
268 @param Length Size in bytes of the copy.
269 @param Buffer Pointer to a system memory buffer containing the data to write.
277 IN UINTN StartAddress
,
279 IN CONST UINT16
*Buffer
282 UINT16
*ReturnBuffer
;
284 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
286 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
287 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
289 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
290 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
292 ReturnBuffer
= (UINT16
*) Buffer
;
295 MmioWrite16 (StartAddress
, *(Buffer
++));
297 StartAddress
+= sizeof (UINT16
);
298 Length
-= sizeof (UINT16
);
306 Copy data from system memory to MMIO region by using 32-bit access.
308 Copy data from system memory specified by Buffer to MMIO region specified
309 by starting address StartAddress by using 32-bit access. The total number
310 of byte to be copied is specified by Length. Buffer is returned.
312 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
314 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
315 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
317 If Length is not aligned on a 32-bit boundary, then ASSERT().
319 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
321 @param StartAddress Starting address for the MMIO region to be copied to.
322 @param Length Size in bytes of the copy.
323 @param Buffer Pointer to a system memory buffer containing the data to write.
331 IN UINTN StartAddress
,
333 IN CONST UINT32
*Buffer
336 UINT32
*ReturnBuffer
;
338 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
340 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
341 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
343 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
344 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
346 ReturnBuffer
= (UINT32
*) Buffer
;
349 MmioWrite32 (StartAddress
, *(Buffer
++));
351 StartAddress
+= sizeof (UINT32
);
352 Length
-= sizeof (UINT32
);
359 Copy data from system memory to MMIO region by using 64-bit access.
361 Copy data from system memory specified by Buffer to MMIO region specified
362 by starting address StartAddress by using 64-bit access. The total number
363 of byte to be copied is specified by Length. Buffer is returned.
365 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
367 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
368 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
370 If Length is not aligned on a 64-bit boundary, then ASSERT().
372 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
374 @param StartAddress Starting address for the MMIO region to be copied to.
375 @param Length Size in bytes of the copy.
376 @param Buffer Pointer to a system memory buffer containing the data to write.
384 IN UINTN StartAddress
,
386 IN CONST UINT64
*Buffer
389 UINT64
*ReturnBuffer
;
391 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
393 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
394 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
396 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
397 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
399 ReturnBuffer
= (UINT64
*) Buffer
;
402 MmioWrite64 (StartAddress
, *(Buffer
++));
404 StartAddress
+= sizeof (UINT64
);
405 Length
-= sizeof (UINT64
);