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