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