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