]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/DxeIoLibCpuIo/IoLibMmioBuffer.c
MdeModulePkg/FaultTolerantWriteDxe: implement standalone MM version
[mirror_edk2.git] / IntelFrameworkPkg / Library / DxeIoLibCpuIo / 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 Module Name: IoLibMmioBuffer.c
14
15 **/
16
17
18 #include "DxeCpuIoLibInternal.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-- > 0) {
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
74 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
75
76 @param StartAddress Starting address for the MMIO region to be copied from.
77 @param Length Size in bytes of the copy.
78 @param Buffer Pointer to a system memory buffer receiving the data read.
79
80 @return Buffer
81
82 **/
83 UINT16 *
84 EFIAPI
85 MmioReadBuffer16 (
86 IN UINTN StartAddress,
87 IN UINTN Length,
88 OUT UINT16 *Buffer
89 )
90 {
91 UINT16 *ReturnBuffer;
92
93 ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);
94
95 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
96 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
97
98 ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);
99 ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);
100
101 ReturnBuffer = Buffer;
102
103 while (Length > 0) {
104 *(Buffer++) = MmioRead16 (StartAddress);
105 StartAddress += sizeof (UINT16);
106 Length -= sizeof (UINT16);
107 }
108
109 return ReturnBuffer;
110 }
111
112 /**
113 Copy data from MMIO region to system memory by using 32-bit access.
114
115 Copy data from MMIO region specified by starting address StartAddress
116 to system memory specified by Buffer by using 32-bit access. The total
117 number of byte to be copied is specified by Length. Buffer is returned.
118
119 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
120
121 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
122 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
123
124 If Length is not aligned on a 32-bit boundary, then ASSERT().
125 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
126
127 @param StartAddress Starting address for the MMIO region to be copied from.
128 @param Length Size in bytes of the copy.
129 @param Buffer Pointer to a system memory buffer receiving the data read.
130
131 @return Buffer
132
133 **/
134 UINT32 *
135 EFIAPI
136 MmioReadBuffer32 (
137 IN UINTN StartAddress,
138 IN UINTN Length,
139 OUT UINT32 *Buffer
140 )
141 {
142 UINT32 *ReturnBuffer;
143
144 ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);
145
146 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
147 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
148
149 ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);
150 ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);
151
152 ReturnBuffer = Buffer;
153
154 while (Length > 0) {
155 *(Buffer++) = MmioRead32 (StartAddress);
156 StartAddress += sizeof (UINT32);
157 Length -= sizeof (UINT32);
158 }
159
160 return ReturnBuffer;
161 }
162
163 /**
164 Copy data from MMIO region to system memory by using 64-bit access.
165
166 Copy data from MMIO region specified by starting address StartAddress
167 to system memory specified by Buffer by using 64-bit access. The total
168 number of byte to be copied is specified by Length. Buffer is returned.
169
170 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
171
172 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
173 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
174
175 If Length is not aligned on a 64-bit boundary, then ASSERT().
176
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 > 0) {
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 Buffer
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-- > 0) {
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. Buffer 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 Buffer
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 > 0) {
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. Buffer 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 Buffer
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 > 0) {
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. Buffer 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 Buffer
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 > 0) {
408 MmioWrite64 (StartAddress, *(Buffer++));
409
410 StartAddress += sizeof (UINT64);
411 Length -= sizeof (UINT64);
412 }
413
414 return ReturnBuffer;
415 }
416