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