VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/BaseIoLibIntrinsic/IoLibMmioBuffer.c@ 107675

最後變更 在這個檔案從107675是 99404,由 vboxsync 提交於 2 年 前

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette