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