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