]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/SmmIoLibSmmCpuIo2/IoLibMmioBuffer.c
MdePkg: Replace BSD License with BSD+Patent License
[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
32 IN UINTN StartAddress,\r
33 IN UINTN Length,\r
34 OUT UINT8 *Buffer\r
35 )\r
36{\r
37 UINT8 *ReturnBuffer;\r
38\r
39 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
40 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
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
77 IN UINTN StartAddress,\r
78 IN UINTN Length,\r
79 OUT UINT16 *Buffer\r
80 )\r
81{\r
82 UINT16 *ReturnBuffer;\r
83\r
84 ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);\r
85\r
86 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
87 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
88\r
89 ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);\r
90 ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);\r
91\r
92 ReturnBuffer = Buffer;\r
93\r
94 while (Length > 0) {\r
95 *(Buffer++) = MmioRead16 (StartAddress);\r
96 StartAddress += sizeof (UINT16);\r
97 Length -= sizeof (UINT16);\r
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
128 IN UINTN StartAddress,\r
129 IN UINTN Length,\r
130 OUT UINT32 *Buffer\r
131 )\r
132{\r
133 UINT32 *ReturnBuffer;\r
134\r
135 ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);\r
136\r
137 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
138 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
139\r
140 ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);\r
141 ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);\r
142\r
143 ReturnBuffer = Buffer;\r
144\r
145 while (Length > 0) {\r
146 *(Buffer++) = MmioRead32 (StartAddress);\r
147 StartAddress += sizeof (UINT32);\r
148 Length -= sizeof (UINT32);\r
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
180 IN UINTN StartAddress,\r
181 IN UINTN Length,\r
182 OUT UINT64 *Buffer\r
183 )\r
184{\r
185 UINT64 *ReturnBuffer;\r
186\r
187 ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);\r
188\r
189 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
190 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
191\r
192 ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);\r
193 ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);\r
194\r
195 ReturnBuffer = Buffer;\r
196\r
197 while (Length > 0) {\r
198 *(Buffer++) = MmioRead64 (StartAddress);\r
199 StartAddress += sizeof (UINT64);\r
200 Length -= sizeof (UINT64);\r
201 }\r
202\r
203 return ReturnBuffer;\r
204}\r
205\r
206\r
207/**\r
208 Copy data from system memory to MMIO region by using 8-bit access.\r
209\r
210 Copy data from system memory specified by Buffer to MMIO region specified\r
211 by starting address StartAddress by using 8-bit access. The total number\r
212 of byte to be copied is specified by Length. Buffer is returned.\r
213\r
214 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
215 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
216\r
217\r
2fc59a00 218 @param StartAddress The starting address for the MMIO region to be copied to.\r
58380e9c 219 @param Length The size in bytes of the copy.\r
9095d37b 220 @param Buffer The pointer to a system memory buffer containing the\r
58380e9c 221 data to write.\r
b7c5912a 222\r
223 @return Buffer\r
224\r
225**/\r
226UINT8 *\r
227EFIAPI\r
228MmioWriteBuffer8 (\r
229 IN UINTN StartAddress,\r
230 IN UINTN Length,\r
231 IN CONST UINT8 *Buffer\r
232 )\r
233{\r
234 VOID* ReturnBuffer;\r
235\r
236 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
237 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
238\r
239 ReturnBuffer = (UINT8 *) Buffer;\r
240\r
241 while (Length-- > 0) {\r
242 MmioWrite8 (StartAddress++, *(Buffer++));\r
243 }\r
244\r
245 return ReturnBuffer;\r
246\r
247}\r
248\r
249/**\r
250 Copy data from system memory to MMIO region by using 16-bit access.\r
251\r
252 Copy data from system memory specified by Buffer to MMIO region specified\r
253 by starting address StartAddress by using 16-bit access. The total number\r
254 of byte to be copied is specified by Length. Buffer is returned.\r
255\r
256 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().\r
257\r
258 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
259 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
260\r
261 If Length is not aligned on a 16-bit boundary, then ASSERT().\r
262\r
263 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
264\r
2fc59a00 265 @param StartAddress The starting address for the MMIO region to be copied to.\r
58380e9c 266 @param Length The size in bytes of the copy.\r
9095d37b 267 @param Buffer The pointer to a system memory buffer containing the\r
58380e9c 268 data to write.\r
b7c5912a 269\r
270 @return Buffer\r
271\r
272**/\r
273UINT16 *\r
274EFIAPI\r
275MmioWriteBuffer16 (\r
276 IN UINTN StartAddress,\r
277 IN UINTN Length,\r
278 IN CONST UINT16 *Buffer\r
279 )\r
280{\r
281 UINT16 *ReturnBuffer;\r
282\r
283 ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);\r
284\r
285 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
286 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
287\r
288 ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);\r
289 ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);\r
290\r
291 ReturnBuffer = (UINT16 *) Buffer;\r
292\r
293 while (Length > 0) {\r
294 MmioWrite16 (StartAddress, *(Buffer++));\r
295\r
296 StartAddress += sizeof (UINT16);\r
297 Length -= sizeof (UINT16);\r
298 }\r
299\r
300 return ReturnBuffer;\r
301}\r
302\r
303\r
304/**\r
305 Copy data from system memory to MMIO region by using 32-bit access.\r
306\r
307 Copy data from system memory specified by Buffer to MMIO region specified\r
308 by starting address StartAddress by using 32-bit access. The total number\r
309 of byte to be copied is specified by Length. Buffer is returned.\r
310\r
311 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().\r
312\r
313 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
314 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
315\r
316 If Length is not aligned on a 32-bit boundary, then ASSERT().\r
317\r
318 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
319\r
2fc59a00 320 @param StartAddress The starting address for the MMIO region to be copied to.\r
58380e9c 321 @param Length The size in bytes of the copy.\r
9095d37b 322 @param Buffer The pointer to a system memory buffer containing the\r
58380e9c 323 data to write.\r
b7c5912a 324\r
325 @return Buffer\r
326\r
327**/\r
328UINT32 *\r
329EFIAPI\r
330MmioWriteBuffer32 (\r
331 IN UINTN StartAddress,\r
332 IN UINTN Length,\r
333 IN CONST UINT32 *Buffer\r
334 )\r
335{\r
336 UINT32 *ReturnBuffer;\r
337\r
338 ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);\r
339\r
340 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
341 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r
342\r
343 ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);\r
344 ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);\r
345\r
346 ReturnBuffer = (UINT32 *) Buffer;\r
347\r
348 while (Length > 0) {\r
349 MmioWrite32 (StartAddress, *(Buffer++));\r
350\r
351 StartAddress += sizeof (UINT32);\r
352 Length -= sizeof (UINT32);\r
353 }\r
354\r
355 return ReturnBuffer;\r
356}\r
357\r
358/**\r
359 Copy data from system memory to MMIO region by using 64-bit access.\r
360\r
361 Copy data from system memory specified by Buffer to MMIO region specified\r
362 by starting address StartAddress by using 64-bit access. The total number\r
363 of byte to be copied is specified by Length. Buffer is returned.\r
364\r
365 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().\r
366\r
367 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
368 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
369\r
370 If Length is not aligned on a 64-bit boundary, then ASSERT().\r
371\r
372 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
373\r
2fc59a00 374 @param StartAddress The starting address for the MMIO region to be copied to.\r
58380e9c 375 @param Length The size in bytes of the copy.\r
9095d37b 376 @param Buffer The pointer to a system memory buffer containing the\r
58380e9c 377 data to write.\r
b7c5912a 378\r
379 @return Buffer\r
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
402 while (Length > 0) {\r
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