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