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