]>
git.proxmox.com Git - mirror_edk2.git/blob - OldMdePkg/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 Copy data from MMIO region to system memory by using 8-bit access.
18 Copy data from MMIO region specified by starting address StartAddress
19 to system memory specified by Buffer by using 8-bit access. The total
20 number of byte to be copied is specified by Length. Buffer is returned.
22 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
23 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
26 @param StartAddress Starting address for the MMIO region to be copied from.
27 @param Length Size in bytes of the copy.
28 @param Buffer Pointer to a system memory buffer receiving the data read.
36 IN UINTN StartAddress
,
43 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
44 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
46 ReturnBuffer
= Buffer
;
49 *(Buffer
++) = MmioRead8 (StartAddress
++);
56 Copy data from MMIO region to system memory by using 16-bit access.
58 Copy data from MMIO region specified by starting address StartAddress
59 to system memory specified by Buffer by using 16-bit access. The total
60 number of byte to be copied is specified by Length. Buffer is returned.
62 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
64 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
65 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
67 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().
170 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
172 @param StartAddress Starting address for the MMIO region to be copied from.
173 @param Length Size in bytes of the copy.
174 @param Buffer Pointer to a system memory buffer receiving the data read.
182 IN UINTN StartAddress
,
187 UINT64
*ReturnBuffer
;
189 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
191 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
192 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
194 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
195 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
197 ReturnBuffer
= Buffer
;
200 *(Buffer
++) = MmioRead64 (StartAddress
);
201 StartAddress
+= sizeof (UINT64
);
202 Length
-= sizeof (UINT64
);
210 Copy data from system memory to MMIO region by using 8-bit access.
212 Copy data from system memory specified by Buffer to MMIO region specified
213 by starting address StartAddress by using 8-bit access. The total number
214 of byte to be copied is specified by Length. Buffer is returned.
216 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
217 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
220 @param StartAddress Starting address for the MMIO region to be copied to.
221 @param Length Size in bytes of the copy.
222 @param Buffer Pointer to a system memory buffer containing the data to write.
224 @return Size in bytes of the copy.
230 IN UINTN StartAddress
,
232 IN CONST UINT8
*Buffer
237 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
238 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
240 ReturnBuffer
= (UINT8
*) Buffer
;
243 MmioWrite8 (StartAddress
++, *(Buffer
++));
251 Copy data from system memory to MMIO region by using 16-bit access.
253 Copy data from system memory specified by Buffer to MMIO region specified
254 by starting address StartAddress by using 16-bit access. The total number
255 of byte to be copied is specified by Length. Length is returned.
257 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
259 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
260 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
262 If Length is not aligned on a 16-bit boundary, then ASSERT().
264 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
266 @param StartAddress Starting address for the MMIO region to be copied to.
267 @param Length Size in bytes of the copy.
268 @param Buffer Pointer to a system memory buffer containing the data to write.
270 @return Size in bytes of the copy.
276 IN UINTN StartAddress
,
278 IN CONST UINT16
*Buffer
281 UINT16
*ReturnBuffer
;
283 ASSERT ((StartAddress
& (sizeof (UINT16
) - 1)) == 0);
285 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
286 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
288 ASSERT ((Length
& (sizeof (UINT16
) - 1)) == 0);
289 ASSERT (((UINTN
) Buffer
& (sizeof (UINT16
) - 1)) == 0);
291 ReturnBuffer
= (UINT16
*) Buffer
;
294 MmioWrite16 (StartAddress
, *(Buffer
++));
296 StartAddress
+= sizeof (UINT16
);
297 Length
-= sizeof (UINT16
);
305 Copy data from system memory to MMIO region by using 32-bit access.
307 Copy data from system memory specified by Buffer to MMIO region specified
308 by starting address StartAddress by using 32-bit access. The total number
309 of byte to be copied is specified by Length. Length is returned.
311 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
313 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
314 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
316 If Length is not aligned on a 32-bit boundary, then ASSERT().
318 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
320 @param StartAddress Starting address for the MMIO region to be copied to.
321 @param Length Size in bytes of the copy.
322 @param Buffer Pointer to a system memory buffer containing the data to write.
324 @return Size in bytes of the copy.
330 IN UINTN StartAddress
,
332 IN CONST UINT32
*Buffer
335 UINT32
*ReturnBuffer
;
337 ASSERT ((StartAddress
& (sizeof (UINT32
) - 1)) == 0);
339 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
340 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
342 ASSERT ((Length
& (sizeof (UINT32
) - 1)) == 0);
343 ASSERT (((UINTN
) Buffer
& (sizeof (UINT32
) - 1)) == 0);
345 ReturnBuffer
= (UINT32
*) Buffer
;
348 MmioWrite32 (StartAddress
, *(Buffer
++));
350 StartAddress
+= sizeof (UINT32
);
351 Length
-= sizeof (UINT32
);
358 Copy data from system memory to MMIO region by using 64-bit access.
360 Copy data from system memory specified by Buffer to MMIO region specified
361 by starting address StartAddress by using 64-bit access. The total number
362 of byte to be copied is specified by Length. Length is returned.
364 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
366 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
367 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
369 If Length is not aligned on a 64-bit boundary, then ASSERT().
371 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
373 @param StartAddress Starting address for the MMIO region to be copied to.
374 @param Length Size in bytes of the copy.
375 @param Buffer Pointer to a system memory buffer containing the data to write.
377 @return Size in bytes of the copy.
383 IN UINTN StartAddress
,
385 IN CONST UINT64
*Buffer
388 UINT64
*ReturnBuffer
;
390 ASSERT ((StartAddress
& (sizeof (UINT64
) - 1)) == 0);
392 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- StartAddress
));
393 ASSERT ((Length
- 1) <= (MAX_ADDRESS
- (UINTN
) Buffer
));
395 ASSERT ((Length
& (sizeof (UINT64
) - 1)) == 0);
396 ASSERT (((UINTN
) Buffer
& (sizeof (UINT64
) - 1)) == 0);
398 ReturnBuffer
= (UINT64
*) Buffer
;
401 MmioWrite64 (StartAddress
, *(Buffer
++));
403 StartAddress
+= sizeof (UINT64
);
404 Length
-= sizeof (UINT64
);