1. add missing inf files
[mirror_edk2.git] / IntelFrameworkPkg / Library / DxeIoLibCpuIo / IoLibMmioBuffer.c
1 /** @file
2 I/O Library MMIO Buffer Functions.
3
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
9
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.
12
13 **/
14
15
16 #include "DxeCpuIoLibInternal.h"
17
18 /**
19 Copy data from MMIO region to system memory by using 8-bit access.
20
21 Copy data from MMIO region specified by starting address StartAddress
22 to system memory specified by Buffer by using 8-bit access. The total
23 number of byte to be copied is specified by Length. Buffer is returned.
24
25 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
26 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
27
28
29 @param StartAddress Starting address for the MMIO region to be copied from.
30 @param Length Size in bytes of the copy.
31 @param Buffer Pointer to a system memory buffer receiving the data read.
32
33 @return Buffer
34
35 **/
36 UINT8 *
37 EFIAPI
38 MmioReadBuffer8 (
39 IN UINTN StartAddress,
40 IN UINTN Length,
41 OUT UINT8 *Buffer
42 )
43 {
44 UINT8 *ReturnBuffer;
45
46 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
47 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
48
49 ReturnBuffer = Buffer;
50
51 while (Length--) {
52 *(Buffer++) = MmioRead8 (StartAddress++);
53 }
54
55 return ReturnBuffer;
56 }
57
58 /**
59 Copy data from MMIO region to system memory by using 16-bit access.
60
61 Copy data from MMIO region specified by starting address StartAddress
62 to system memory specified by Buffer by using 16-bit access. The total
63 number of byte to be copied is specified by Length. Buffer is returned.
64
65 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
66
67 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
68 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
69
70 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().
72
73 @param StartAddress Starting address for the MMIO region to be copied from.
74 @param Length Size in bytes of the copy.
75 @param Buffer Pointer to a system memory buffer receiving the data read.
76
77 @return Buffer
78
79 **/
80 UINT16 *
81 EFIAPI
82 MmioReadBuffer16 (
83 IN UINTN StartAddress,
84 IN UINTN Length,
85 OUT UINT16 *Buffer
86 )
87 {
88 UINT16 *ReturnBuffer;
89
90 ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);
91
92 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
93 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
94
95 ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);
96 ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);
97
98 ReturnBuffer = Buffer;
99
100 while (Length) {
101 *(Buffer++) = MmioRead16 (StartAddress);
102 StartAddress += sizeof (UINT16);
103 Length -= sizeof (UINT16);
104 }
105
106 return ReturnBuffer;
107 }
108
109 /**
110 Copy data from MMIO region to system memory by using 32-bit access.
111
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.
115
116 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
117
118 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
119 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
120
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().
123
124 @param StartAddress Starting address for the MMIO region to be copied from.
125 @param Length Size in bytes of the copy.
126 @param Buffer Pointer to a system memory buffer receiving the data read.
127
128 @return Buffer
129
130 **/
131 UINT32 *
132 EFIAPI
133 MmioReadBuffer32 (
134 IN UINTN StartAddress,
135 IN UINTN Length,
136 OUT UINT32 *Buffer
137 )
138 {
139 UINT32 *ReturnBuffer;
140
141 ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);
142
143 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
144 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
145
146 ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);
147 ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);
148
149 ReturnBuffer = Buffer;
150
151 while (Length) {
152 *(Buffer++) = MmioRead32 (StartAddress);
153 StartAddress += sizeof (UINT32);
154 Length -= sizeof (UINT32);
155 }
156
157 return ReturnBuffer;
158 }
159
160 /**
161 Copy data from MMIO region to system memory by using 64-bit access.
162
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.
166
167 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
168
169 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
170 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
171
172 If Length is not aligned on a 64-bit boundary, then ASSERT().
173 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
174
175 @param StartAddress Starting address for the MMIO region to be copied from.
176 @param Length Size in bytes of the copy.
177 @param Buffer Pointer to a system memory buffer receiving the data read.
178
179 @return Buffer
180
181 **/
182 UINT64 *
183 EFIAPI
184 MmioReadBuffer64 (
185 IN UINTN StartAddress,
186 IN UINTN Length,
187 OUT UINT64 *Buffer
188 )
189 {
190 UINT64 *ReturnBuffer;
191
192 ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);
193
194 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
195 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
196
197 ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);
198 ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);
199
200 ReturnBuffer = Buffer;
201
202 while (Length) {
203 *(Buffer++) = MmioRead64 (StartAddress);
204 StartAddress += sizeof (UINT64);
205 Length -= sizeof (UINT64);
206 }
207
208 return ReturnBuffer;
209 }
210
211
212 /**
213 Copy data from system memory to MMIO region by using 8-bit access.
214
215 Copy data from system memory specified by Buffer to MMIO region specified
216 by starting address StartAddress by using 8-bit access. The total number
217 of byte to be copied is specified by Length. Buffer is returned.
218
219 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
220 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
221
222
223 @param StartAddress Starting address for the MMIO region to be copied to.
224 @param Length Size in bytes of the copy.
225 @param Buffer Pointer to a system memory buffer containing the data to write.
226
227 @return Size in bytes of the copy.
228
229 **/
230 UINT8 *
231 EFIAPI
232 MmioWriteBuffer8 (
233 IN UINTN StartAddress,
234 IN UINTN Length,
235 IN CONST UINT8 *Buffer
236 )
237 {
238 VOID* ReturnBuffer;
239
240 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
241 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
242
243 ReturnBuffer = (UINT8 *) Buffer;
244
245 while (Length--) {
246 MmioWrite8 (StartAddress++, *(Buffer++));
247 }
248
249 return ReturnBuffer;
250
251 }
252
253 /**
254 Copy data from system memory to MMIO region by using 16-bit access.
255
256 Copy data from system memory specified by Buffer to MMIO region specified
257 by starting address StartAddress by using 16-bit access. The total number
258 of byte to be copied is specified by Length. Length is returned.
259
260 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
261
262 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
263 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
264
265 If Length is not aligned on a 16-bit boundary, then ASSERT().
266
267 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
268
269 @param StartAddress Starting address for the MMIO region to be copied to.
270 @param Length Size in bytes of the copy.
271 @param Buffer Pointer to a system memory buffer containing the data to write.
272
273 @return Size in bytes of the copy.
274
275 **/
276 UINT16 *
277 EFIAPI
278 MmioWriteBuffer16 (
279 IN UINTN StartAddress,
280 IN UINTN Length,
281 IN CONST UINT16 *Buffer
282 )
283 {
284 UINT16 *ReturnBuffer;
285
286 ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);
287
288 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
289 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
290
291 ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);
292 ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);
293
294 ReturnBuffer = (UINT16 *) Buffer;
295
296 while (Length) {
297 MmioWrite16 (StartAddress, *(Buffer++));
298
299 StartAddress += sizeof (UINT16);
300 Length -= sizeof (UINT16);
301 }
302
303 return ReturnBuffer;
304 }
305
306
307 /**
308 Copy data from system memory to MMIO region by using 32-bit access.
309
310 Copy data from system memory specified by Buffer to MMIO region specified
311 by starting address StartAddress by using 32-bit access. The total number
312 of byte to be copied is specified by Length. Length is returned.
313
314 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
315
316 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
317 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
318
319 If Length is not aligned on a 32-bit boundary, then ASSERT().
320
321 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
322
323 @param StartAddress Starting address for the MMIO region to be copied to.
324 @param Length Size in bytes of the copy.
325 @param Buffer Pointer to a system memory buffer containing the data to write.
326
327 @return Size in bytes of the copy.
328
329 **/
330 UINT32 *
331 EFIAPI
332 MmioWriteBuffer32 (
333 IN UINTN StartAddress,
334 IN UINTN Length,
335 IN CONST UINT32 *Buffer
336 )
337 {
338 UINT32 *ReturnBuffer;
339
340 ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);
341
342 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
343 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
344
345 ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);
346 ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);
347
348 ReturnBuffer = (UINT32 *) Buffer;
349
350 while (Length) {
351 MmioWrite32 (StartAddress, *(Buffer++));
352
353 StartAddress += sizeof (UINT32);
354 Length -= sizeof (UINT32);
355 }
356
357 return ReturnBuffer;
358 }
359
360 /**
361 Copy data from system memory to MMIO region by using 64-bit access.
362
363 Copy data from system memory specified by Buffer to MMIO region specified
364 by starting address StartAddress by using 64-bit access. The total number
365 of byte to be copied is specified by Length. Length is returned.
366
367 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
368
369 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
370 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
371
372 If Length is not aligned on a 64-bit boundary, then ASSERT().
373
374 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
375
376 @param StartAddress Starting address for the MMIO region to be copied to.
377 @param Length Size in bytes of the copy.
378 @param Buffer Pointer to a system memory buffer containing the data to write.
379
380 @return Size in bytes of the copy.
381
382 **/
383 UINT64 *
384 EFIAPI
385 MmioWriteBuffer64 (
386 IN UINTN StartAddress,
387 IN UINTN Length,
388 IN CONST UINT64 *Buffer
389 )
390 {
391 UINT64 *ReturnBuffer;
392
393 ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);
394
395 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
396 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
397
398 ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);
399 ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);
400
401 ReturnBuffer = (UINT64 *) Buffer;
402
403 while (Length) {
404 MmioWrite64 (StartAddress, *(Buffer++));
405
406 StartAddress += sizeof (UINT64);
407 Length -= sizeof (UINT64);
408 }
409
410 return ReturnBuffer;
411 }
412