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