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