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 | **/
|
---|
29 | UINT8 *
|
---|
30 | EFIAPI
|
---|
31 | MmioReadBuffer8 (
|
---|
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 | **/
|
---|
73 | UINT16 *
|
---|
74 | EFIAPI
|
---|
75 | MmioReadBuffer16 (
|
---|
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 | **/
|
---|
124 | UINT32 *
|
---|
125 | EFIAPI
|
---|
126 | MmioReadBuffer32 (
|
---|
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 | **/
|
---|
175 | UINT64 *
|
---|
176 | EFIAPI
|
---|
177 | MmioReadBuffer64 (
|
---|
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 | /**
|
---|
206 | Copy data from system memory to the MMIO region by using 8-bit access.
|
---|
207 |
|
---|
208 | Copy data from system memory specified by Buffer to the MMIO region specified
|
---|
209 | by starting address StartAddress by using 8-bit access. The total number
|
---|
210 | of byte to be copied is specified by Length. Buffer is returned.
|
---|
211 |
|
---|
212 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
|
---|
213 | If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
|
---|
214 |
|
---|
215 |
|
---|
216 | @param StartAddress The starting address for the MMIO region to be copied to.
|
---|
217 | @param Length The size, in bytes, of Buffer.
|
---|
218 | @param Buffer The pointer to a system memory buffer containing the data to write.
|
---|
219 |
|
---|
220 | @return Buffer
|
---|
221 |
|
---|
222 | **/
|
---|
223 | UINT8 *
|
---|
224 | EFIAPI
|
---|
225 | MmioWriteBuffer8 (
|
---|
226 | IN UINTN StartAddress,
|
---|
227 | IN UINTN Length,
|
---|
228 | IN CONST UINT8 *Buffer
|
---|
229 | )
|
---|
230 | {
|
---|
231 | VOID* ReturnBuffer;
|
---|
232 |
|
---|
233 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
|
---|
234 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
|
---|
235 |
|
---|
236 | ReturnBuffer = (UINT8 *) Buffer;
|
---|
237 |
|
---|
238 | while (Length-- != 0) {
|
---|
239 | MmioWrite8 (StartAddress++, *(Buffer++));
|
---|
240 | }
|
---|
241 |
|
---|
242 | return ReturnBuffer;
|
---|
243 |
|
---|
244 | }
|
---|
245 |
|
---|
246 | /**
|
---|
247 | Copy data from system memory to the MMIO region by using 16-bit access.
|
---|
248 |
|
---|
249 | Copy data from system memory specified by Buffer to the MMIO region specified
|
---|
250 | by starting address StartAddress by using 16-bit access. The total number
|
---|
251 | of byte to be copied is specified by Length. Buffer is returned.
|
---|
252 |
|
---|
253 | If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
|
---|
254 |
|
---|
255 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
|
---|
256 | If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
|
---|
257 |
|
---|
258 | If Length is not aligned on a 16-bit boundary, then ASSERT().
|
---|
259 |
|
---|
260 | If Buffer is not aligned on a 16-bit boundary, then ASSERT().
|
---|
261 |
|
---|
262 | @param StartAddress The starting address for the MMIO region to be copied to.
|
---|
263 | @param Length The size, in bytes, of Buffer.
|
---|
264 | @param Buffer The pointer to a system memory buffer containing the data to write.
|
---|
265 |
|
---|
266 | @return Buffer
|
---|
267 |
|
---|
268 | **/
|
---|
269 | UINT16 *
|
---|
270 | EFIAPI
|
---|
271 | MmioWriteBuffer16 (
|
---|
272 | IN UINTN StartAddress,
|
---|
273 | IN UINTN Length,
|
---|
274 | IN CONST UINT16 *Buffer
|
---|
275 | )
|
---|
276 | {
|
---|
277 | UINT16 *ReturnBuffer;
|
---|
278 |
|
---|
279 | ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);
|
---|
280 |
|
---|
281 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
|
---|
282 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
|
---|
283 |
|
---|
284 | ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);
|
---|
285 | ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);
|
---|
286 |
|
---|
287 | ReturnBuffer = (UINT16 *) Buffer;
|
---|
288 |
|
---|
289 | while (Length != 0) {
|
---|
290 | MmioWrite16 (StartAddress, *(Buffer++));
|
---|
291 |
|
---|
292 | StartAddress += sizeof (UINT16);
|
---|
293 | Length -= sizeof (UINT16);
|
---|
294 | }
|
---|
295 |
|
---|
296 | return ReturnBuffer;
|
---|
297 | }
|
---|
298 |
|
---|
299 |
|
---|
300 | /**
|
---|
301 | Copy data from system memory to the MMIO region by using 32-bit access.
|
---|
302 |
|
---|
303 | Copy data from system memory specified by Buffer to the MMIO region specified
|
---|
304 | by starting address StartAddress by using 32-bit access. The total number
|
---|
305 | of byte to be copied is specified by Length. Buffer is returned.
|
---|
306 |
|
---|
307 | If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
|
---|
308 |
|
---|
309 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
|
---|
310 | If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
|
---|
311 |
|
---|
312 | If Length is not aligned on a 32-bit boundary, then ASSERT().
|
---|
313 |
|
---|
314 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().
|
---|
315 |
|
---|
316 | @param StartAddress The starting address for the MMIO region to be copied to.
|
---|
317 | @param Length The size, in bytes, of Buffer.
|
---|
318 | @param Buffer The pointer to a system memory buffer containing the data to write.
|
---|
319 |
|
---|
320 | @return Buffer
|
---|
321 |
|
---|
322 | **/
|
---|
323 | UINT32 *
|
---|
324 | EFIAPI
|
---|
325 | MmioWriteBuffer32 (
|
---|
326 | IN UINTN StartAddress,
|
---|
327 | IN UINTN Length,
|
---|
328 | IN CONST UINT32 *Buffer
|
---|
329 | )
|
---|
330 | {
|
---|
331 | UINT32 *ReturnBuffer;
|
---|
332 |
|
---|
333 | ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);
|
---|
334 |
|
---|
335 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
|
---|
336 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
|
---|
337 |
|
---|
338 | ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);
|
---|
339 | ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);
|
---|
340 |
|
---|
341 | ReturnBuffer = (UINT32 *) Buffer;
|
---|
342 |
|
---|
343 | while (Length != 0) {
|
---|
344 | MmioWrite32 (StartAddress, *(Buffer++));
|
---|
345 |
|
---|
346 | StartAddress += sizeof (UINT32);
|
---|
347 | Length -= sizeof (UINT32);
|
---|
348 | }
|
---|
349 |
|
---|
350 | return ReturnBuffer;
|
---|
351 | }
|
---|
352 |
|
---|
353 | /**
|
---|
354 | Copy data from system memory to the MMIO region by using 64-bit access.
|
---|
355 |
|
---|
356 | Copy data from system memory specified by Buffer to the MMIO region specified
|
---|
357 | by starting address StartAddress by using 64-bit access. The total number
|
---|
358 | of byte to be copied is specified by Length. Buffer is returned.
|
---|
359 |
|
---|
360 | If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
|
---|
361 |
|
---|
362 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
|
---|
363 | If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
|
---|
364 |
|
---|
365 | If Length is not aligned on a 64-bit boundary, then ASSERT().
|
---|
366 |
|
---|
367 | If Buffer is not aligned on a 64-bit boundary, then ASSERT().
|
---|
368 |
|
---|
369 | @param StartAddress The starting address for the MMIO region to be copied to.
|
---|
370 | @param Length The size, in bytes, of Buffer.
|
---|
371 | @param Buffer The pointer to a system memory buffer containing the data to write.
|
---|
372 |
|
---|
373 | @return Buffer
|
---|
374 |
|
---|
375 | **/
|
---|
376 | UINT64 *
|
---|
377 | EFIAPI
|
---|
378 | MmioWriteBuffer64 (
|
---|
379 | IN UINTN StartAddress,
|
---|
380 | IN UINTN Length,
|
---|
381 | IN CONST UINT64 *Buffer
|
---|
382 | )
|
---|
383 | {
|
---|
384 | UINT64 *ReturnBuffer;
|
---|
385 |
|
---|
386 | ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);
|
---|
387 |
|
---|
388 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
|
---|
389 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
|
---|
390 |
|
---|
391 | ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);
|
---|
392 | ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);
|
---|
393 |
|
---|
394 | ReturnBuffer = (UINT64 *) Buffer;
|
---|
395 |
|
---|
396 | while (Length != 0) {
|
---|
397 | MmioWrite64 (StartAddress, *(Buffer++));
|
---|
398 |
|
---|
399 | StartAddress += sizeof (UINT64);
|
---|
400 | Length -= sizeof (UINT64);
|
---|
401 | }
|
---|
402 |
|
---|
403 | return ReturnBuffer;
|
---|
404 | }
|
---|
405 |
|
---|