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