]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/DxeIoLibCpuIo2/IoLibMmioBuffer.c
ArmPlatformPkg/PL111LcdArmVExpressLib: use write-combine mapping for VRAM
[mirror_edk2.git] / MdePkg / Library / DxeIoLibCpuIo2 / IoLibMmioBuffer.c
CommitLineData
ba9f8351 1/** @file\r
2 I/O Library MMIO Buffer Functions.\r
3\r
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials are licensed and made available\r
6 under the terms and conditions of the BSD License which accompanies this\r
7 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#include "DxeCpuIo2LibInternal.h"\r
16\r
17/**\r
18 Copy data from MMIO region to system memory by using 8-bit access.\r
19\r
20 Copy data from MMIO region specified by starting address StartAddress\r
21 to system memory specified by Buffer by using 8-bit access. The total\r
22 number of byte to be copied is specified by Length. Buffer is returned.\r
23\r
24 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
25 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
26\r
27\r
2fc59a00 28 @param StartAddress The starting address for the MMIO region to be copied from.\r
29 @param Length The size in bytes of the copy.\r
30 @param Buffer The pointer to a system memory buffer receiving the data read.\r
ba9f8351 31\r
32 @return Buffer\r
33\r
34**/\r
35UINT8 *\r
36EFIAPI\r
37MmioReadBuffer8 (\r
38 IN UINTN StartAddress,\r
39 IN UINTN Length,\r
40 OUT UINT8 *Buffer\r
41 )\r
42{\r
43 UINT8 *ReturnBuffer;\r
44\r
45 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
46 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
47\r
48 ReturnBuffer = Buffer;\r
49\r
50 while (Length-- > 0) {\r
51 *(Buffer++) = MmioRead8 (StartAddress++);\r
52 }\r
53\r
54 return ReturnBuffer;\r
55}\r
56\r
57/**\r
58 Copy data from MMIO region to system memory by using 16-bit access.\r
59\r
60 Copy data from MMIO region specified by starting address StartAddress\r
61 to system memory specified by Buffer by using 16-bit access. The total\r
62 number of byte to be copied is specified by Length. Buffer is returned.\r
63\r
64 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().\r
65\r
66 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
67 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
68\r
69 If Length is not aligned on a 16-bit boundary, then ASSERT().\r
70 \r
71 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
72\r
2fc59a00 73 @param StartAddress The starting address for the MMIO region to be copied from.\r
74 @param Length The size in bytes of the copy.\r
75 @param Buffer The pointer to a system memory buffer receiving the data read.\r
ba9f8351 76\r
58380e9c 77 @return Buffer.\r
ba9f8351 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 > 0) {\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
2fc59a00 124 @param StartAddress The starting address for the MMIO region to be copied from.\r
125 @param Length The size in bytes of the copy.\r
126 @param Buffer The pointer to a system memory buffer receiving the data read.\r
ba9f8351 127\r
58380e9c 128 @return Buffer.\r
ba9f8351 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 > 0) {\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 \r
174 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
175\r
2fc59a00 176 @param StartAddress The starting address for the MMIO region to be copied from.\r
177 @param Length The size in bytes of the copy.\r
178 @param Buffer The pointer to a system memory buffer receiving the data read.\r
ba9f8351 179\r
58380e9c 180 @return Buffer.\r
ba9f8351 181\r
182**/\r
183UINT64 *\r
184EFIAPI\r
185MmioReadBuffer64 (\r
186 IN UINTN StartAddress,\r
187 IN UINTN Length,\r
188 OUT UINT64 *Buffer\r
189 )\r
190{\r
191 UINT64 *ReturnBuffer;\r
192\r
193 ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);\r
194\r
195 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
196 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
197\r
198 ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);\r
199 ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);\r
200\r
201 ReturnBuffer = Buffer;\r
202\r
203 while (Length > 0) {\r
204 *(Buffer++) = MmioRead64 (StartAddress);\r
205 StartAddress += sizeof (UINT64);\r
206 Length -= sizeof (UINT64);\r
207 }\r
208\r
209 return ReturnBuffer;\r
210}\r
211\r
212\r
213/**\r
214 Copy data from system memory to MMIO region by using 8-bit access.\r
215\r
216 Copy data from system memory specified by Buffer to MMIO region specified\r
217 by starting address StartAddress by using 8-bit access. The total number\r
218 of byte to be copied is specified by Length. Buffer is returned.\r
219\r
220 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
221 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
222\r
223\r
2fc59a00 224 @param StartAddress The starting address for the MMIO region to be copied to.\r
58380e9c 225 @param Length The size in bytes of the copy.\r
2fc59a00 226 @param Buffer The pointer to a system memory buffer containing the data to write.\r
ba9f8351 227\r
58380e9c 228 @return Buffer.\r
ba9f8351 229\r
230**/\r
231UINT8 *\r
232EFIAPI\r
233MmioWriteBuffer8 (\r
234 IN UINTN StartAddress,\r
235 IN UINTN Length,\r
236 IN CONST UINT8 *Buffer\r
237 )\r
238{\r
239 VOID* ReturnBuffer;\r
240\r
241 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
242 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
243\r
244 ReturnBuffer = (UINT8 *) Buffer;\r
245\r
246 while (Length-- > 0) {\r
247 MmioWrite8 (StartAddress++, *(Buffer++));\r
248 }\r
249\r
250 return ReturnBuffer;\r
251\r
252}\r
253\r
254/**\r
255 Copy data from system memory to MMIO region by using 16-bit access.\r
256\r
257 Copy data from system memory specified by Buffer to MMIO region specified\r
258 by starting address StartAddress by using 16-bit access. The total number\r
259 of byte to be copied is specified by Length. Buffer is returned.\r
260\r
261 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().\r
262\r
263 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
264 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
265\r
266 If Length is not aligned on a 16-bit boundary, then ASSERT().\r
267\r
268 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
269\r
2fc59a00 270 @param StartAddress The starting address for the MMIO region to be copied to.\r
58380e9c 271 @param Length The size in bytes of the copy.\r
2fc59a00 272 @param Buffer The pointer to a system memory buffer containing the data to write.\r
ba9f8351 273\r
58380e9c 274 @return Buffer.\r
ba9f8351 275\r
276**/\r
277UINT16 *\r
278EFIAPI\r
279MmioWriteBuffer16 (\r
280 IN UINTN StartAddress,\r
281 IN UINTN Length,\r
282 IN CONST UINT16 *Buffer\r
283 )\r
284{\r
285 UINT16 *ReturnBuffer;\r
286\r
287 ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);\r
288\r
289 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
290 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
291\r
292 ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);\r
293 ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);\r
294\r
295 ReturnBuffer = (UINT16 *) Buffer;\r
296\r
297 while (Length > 0) {\r
298 MmioWrite16 (StartAddress, *(Buffer++));\r
299\r
300 StartAddress += sizeof (UINT16);\r
301 Length -= sizeof (UINT16);\r
302 }\r
303\r
304 return ReturnBuffer;\r
305}\r
306\r
307\r
308/**\r
309 Copy data from system memory to MMIO region by using 32-bit access.\r
310\r
311 Copy data from system memory specified by Buffer to MMIO region specified\r
312 by starting address StartAddress by using 32-bit access. The total number\r
313 of byte to be copied is specified by Length. Buffer is returned.\r
314\r
315 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().\r
316\r
317 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
318 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
319\r
320 If Length is not aligned on a 32-bit boundary, then ASSERT().\r
321\r
322 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
323\r
2fc59a00 324 @param StartAddress The starting address for the MMIO region to be copied to.\r
58380e9c 325 @param Length The size in bytes of the copy.\r
2fc59a00 326 @param Buffer The pointer to a system memory buffer containing the data to write.\r
ba9f8351 327\r
58380e9c 328 @return Buffer.\r
ba9f8351 329\r
330**/\r
331UINT32 *\r
332EFIAPI\r
333MmioWriteBuffer32 (\r
334 IN UINTN StartAddress,\r
335 IN UINTN Length,\r
336 IN CONST UINT32 *Buffer\r
337 )\r
338{\r
339 UINT32 *ReturnBuffer;\r
340\r
341 ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);\r
342\r
343 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
344 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
345\r
346 ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);\r
347 ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);\r
348\r
349 ReturnBuffer = (UINT32 *) Buffer;\r
350\r
351 while (Length > 0) {\r
352 MmioWrite32 (StartAddress, *(Buffer++));\r
353\r
354 StartAddress += sizeof (UINT32);\r
355 Length -= sizeof (UINT32);\r
356 }\r
357\r
358 return ReturnBuffer;\r
359}\r
360\r
361/**\r
362 Copy data from system memory to MMIO region by using 64-bit access.\r
363\r
364 Copy data from system memory specified by Buffer to MMIO region specified\r
365 by starting address StartAddress by using 64-bit access. The total number\r
366 of byte to be copied is specified by Length. Buffer is returned.\r
367\r
368 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().\r
369\r
370 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
371 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
372\r
373 If Length is not aligned on a 64-bit boundary, then ASSERT().\r
374\r
375 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
376\r
2fc59a00 377 @param StartAddress The starting address for the MMIO region to be copied to.\r
58380e9c 378 @param Length The size in bytes of the copy.\r
2fc59a00 379 @param Buffer The pointer to a system memory buffer containing the data to write.\r
ba9f8351 380\r
58380e9c 381 @return Buffer.\r
ba9f8351 382\r
383**/\r
384UINT64 *\r
385EFIAPI\r
386MmioWriteBuffer64 (\r
387 IN UINTN StartAddress,\r
388 IN UINTN Length,\r
389 IN CONST UINT64 *Buffer\r
390 )\r
391{\r
392 UINT64 *ReturnBuffer;\r
393\r
394 ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);\r
395\r
396 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
397 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
398\r
399 ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);\r
400 ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);\r
401\r
402 ReturnBuffer = (UINT64 *) Buffer;\r
403\r
404 while (Length > 0) {\r
405 MmioWrite64 (StartAddress, *(Buffer++));\r
406\r
407 StartAddress += sizeof (UINT64);\r
408 Length -= sizeof (UINT64);\r
409 }\r
410\r
411 return ReturnBuffer;\r
412}\r
413\r