]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/DxeIoLibCpuIo2/IoLibMmioBuffer.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / DxeIoLibCpuIo2 / IoLibMmioBuffer.c
... / ...
CommitLineData
1/** @file\r
2 I/O Library MMIO Buffer Functions.\r
3\r
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#include "DxeCpuIo2LibInternal.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
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
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
64\r
65 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
66\r
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
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
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
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
167\r
168 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
169\r
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
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 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
217 @param StartAddress The starting address for the MMIO region to be copied to.\r
218 @param Length The size in bytes of the copy.\r
219 @param Buffer The pointer to a system memory buffer containing the data to write.\r
220\r
221 @return Buffer.\r
222\r
223**/\r
224UINT8 *\r
225EFIAPI\r
226MmioWriteBuffer8 (\r
227 IN UINTN StartAddress,\r
228 IN UINTN Length,\r
229 IN CONST UINT8 *Buffer\r
230 )\r
231{\r
232 VOID *ReturnBuffer;\r
233\r
234 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
235 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
236\r
237 ReturnBuffer = (UINT8 *)Buffer;\r
238\r
239 while (Length-- > 0) {\r
240 MmioWrite8 (StartAddress++, *(Buffer++));\r
241 }\r
242\r
243 return ReturnBuffer;\r
244}\r
245\r
246/**\r
247 Copy data from system memory to MMIO region by using 16-bit access.\r
248\r
249 Copy data from system memory specified by Buffer to MMIO region specified\r
250 by starting address StartAddress by using 16-bit access. The total number\r
251 of byte to be copied is specified by Length. Buffer is returned.\r
252\r
253 If StartAddress is not aligned on a 16-bit boundary, then ASSERT().\r
254\r
255 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
256 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
257\r
258 If Length is not aligned on a 16-bit boundary, then ASSERT().\r
259\r
260 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
261\r
262 @param StartAddress The starting address for the MMIO region to be copied to.\r
263 @param Length The size in bytes of the copy.\r
264 @param Buffer The pointer to a system memory buffer containing the data to write.\r
265\r
266 @return Buffer.\r
267\r
268**/\r
269UINT16 *\r
270EFIAPI\r
271MmioWriteBuffer16 (\r
272 IN UINTN StartAddress,\r
273 IN UINTN Length,\r
274 IN CONST UINT16 *Buffer\r
275 )\r
276{\r
277 UINT16 *ReturnBuffer;\r
278\r
279 ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);\r
280\r
281 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
282 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
283\r
284 ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);\r
285 ASSERT (((UINTN)Buffer & (sizeof (UINT16) - 1)) == 0);\r
286\r
287 ReturnBuffer = (UINT16 *)Buffer;\r
288\r
289 while (Length > 0) {\r
290 MmioWrite16 (StartAddress, *(Buffer++));\r
291\r
292 StartAddress += sizeof (UINT16);\r
293 Length -= sizeof (UINT16);\r
294 }\r
295\r
296 return ReturnBuffer;\r
297}\r
298\r
299/**\r
300 Copy data from system memory to MMIO region by using 32-bit access.\r
301\r
302 Copy data from system memory specified by Buffer to MMIO region specified\r
303 by starting address StartAddress by using 32-bit access. The total number\r
304 of byte to be copied is specified by Length. Buffer is returned.\r
305\r
306 If StartAddress is not aligned on a 32-bit boundary, then ASSERT().\r
307\r
308 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
309 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
310\r
311 If Length is not aligned on a 32-bit boundary, then ASSERT().\r
312\r
313 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
314\r
315 @param StartAddress The starting address for the MMIO region to be copied to.\r
316 @param Length The size in bytes of the copy.\r
317 @param Buffer The pointer to a system memory buffer containing the data to write.\r
318\r
319 @return Buffer.\r
320\r
321**/\r
322UINT32 *\r
323EFIAPI\r
324MmioWriteBuffer32 (\r
325 IN UINTN StartAddress,\r
326 IN UINTN Length,\r
327 IN CONST UINT32 *Buffer\r
328 )\r
329{\r
330 UINT32 *ReturnBuffer;\r
331\r
332 ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);\r
333\r
334 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
335 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
336\r
337 ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);\r
338 ASSERT (((UINTN)Buffer & (sizeof (UINT32) - 1)) == 0);\r
339\r
340 ReturnBuffer = (UINT32 *)Buffer;\r
341\r
342 while (Length > 0) {\r
343 MmioWrite32 (StartAddress, *(Buffer++));\r
344\r
345 StartAddress += sizeof (UINT32);\r
346 Length -= sizeof (UINT32);\r
347 }\r
348\r
349 return ReturnBuffer;\r
350}\r
351\r
352/**\r
353 Copy data from system memory to MMIO region by using 64-bit access.\r
354\r
355 Copy data from system memory specified by Buffer to MMIO region specified\r
356 by starting address StartAddress by using 64-bit access. The total number\r
357 of byte to be copied is specified by Length. Buffer is returned.\r
358\r
359 If StartAddress is not aligned on a 64-bit boundary, then ASSERT().\r
360\r
361 If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r
362 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r
363\r
364 If Length is not aligned on a 64-bit boundary, then ASSERT().\r
365\r
366 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
367\r
368 @param StartAddress The starting address for the MMIO region to be copied to.\r
369 @param Length The size in bytes of the copy.\r
370 @param Buffer The pointer to a system memory buffer containing the data to write.\r
371\r
372 @return Buffer.\r
373\r
374**/\r
375UINT64 *\r
376EFIAPI\r
377MmioWriteBuffer64 (\r
378 IN UINTN StartAddress,\r
379 IN UINTN Length,\r
380 IN CONST UINT64 *Buffer\r
381 )\r
382{\r
383 UINT64 *ReturnBuffer;\r
384\r
385 ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);\r
386\r
387 ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r
388 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
389\r
390 ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);\r
391 ASSERT (((UINTN)Buffer & (sizeof (UINT64) - 1)) == 0);\r
392\r
393 ReturnBuffer = (UINT64 *)Buffer;\r
394\r
395 while (Length > 0) {\r
396 MmioWrite64 (StartAddress, *(Buffer++));\r
397\r
398 StartAddress += sizeof (UINT64);\r
399 Length -= sizeof (UINT64);\r
400 }\r
401\r
402 return ReturnBuffer;\r
403}\r