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