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