]>
Commit | Line | Data |
---|---|---|
863be5d0 | 1 | /** @file\r |
2 | I/O Library MMIO Buffer Functions.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php.\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "DxeIoLibEsalInternal.h"\r | |
16 | \r | |
17 | /**\r | |
18 | Copy data from MMIO region to system memory by using 8-bit access.\r | |
19 | \r | |
20 | Copy data from MMIO region specified by starting address StartAddress \r | |
21 | to system memory specified by Buffer by using 8-bit access. The total \r | |
22 | number of byte to be copied is specified by Length. Buffer is returned.\r | |
23 | \r | |
24 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT(). \r | |
25 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
26 | \r | |
27 | \r | |
28 | @param StartAddress Starting address for the MMIO region to be copied from.\r | |
29 | @param Length Size in bytes of the copy.\r | |
30 | @param Buffer Pointer to a system memory buffer receiving the data read.\r | |
31 | \r | |
32 | @return Buffer\r | |
33 | \r | |
34 | **/\r | |
35 | UINT8 *\r | |
36 | EFIAPI\r | |
37 | MmioReadBuffer8 (\r | |
38 | IN UINTN StartAddress,\r | |
39 | IN UINTN Length,\r | |
40 | OUT UINT8 *Buffer\r | |
41 | )\r | |
42 | {\r | |
43 | UINT8 *ReturnBuffer;\r | |
44 | \r | |
45 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
46 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
47 | \r | |
48 | ReturnBuffer = Buffer;\r | |
49 | \r | |
50 | while (Length-- > 0) {\r | |
51 | *(Buffer++) = MmioRead8 (StartAddress++);\r | |
52 | }\r | |
53 | \r | |
54 | return ReturnBuffer;\r | |
55 | }\r | |
56 | \r | |
57 | /**\r | |
58 | Copy data from MMIO region to system memory by using 16-bit access.\r | |
59 | \r | |
60 | Copy data from MMIO region specified by starting address StartAddress \r | |
61 | to system memory specified by Buffer by using 16-bit access. The total \r | |
62 | number of byte to be copied is specified by Length. Buffer is returned.\r | |
63 | \r | |
64 | If StartAddress is not aligned on a 16-bit boundary, then ASSERT().\r | |
65 | \r | |
66 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT(). \r | |
67 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
68 | \r | |
69 | If Length is not aligned on a 16-bit boundary, then ASSERT().\r | |
70 | If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r | |
71 | \r | |
72 | @param StartAddress Starting address for the MMIO region to be copied from.\r | |
73 | @param Length Size in bytes of the copy.\r | |
74 | @param Buffer Pointer to a system memory buffer receiving the data read.\r | |
75 | \r | |
76 | @return Buffer\r | |
77 | \r | |
78 | **/\r | |
79 | UINT16 *\r | |
80 | EFIAPI\r | |
81 | MmioReadBuffer16 (\r | |
82 | IN UINTN StartAddress,\r | |
83 | IN UINTN Length,\r | |
84 | OUT UINT16 *Buffer\r | |
85 | )\r | |
86 | {\r | |
87 | UINT16 *ReturnBuffer;\r | |
88 | \r | |
89 | ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);\r | |
90 | \r | |
91 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
92 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
93 | \r | |
94 | ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);\r | |
95 | ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);\r | |
96 | \r | |
97 | ReturnBuffer = Buffer;\r | |
98 | \r | |
99 | while (Length > 0) {\r | |
100 | *(Buffer++) = MmioRead16 (StartAddress);\r | |
101 | StartAddress += sizeof (UINT16);\r | |
102 | Length -= sizeof (UINT16);\r | |
103 | }\r | |
104 | \r | |
105 | return ReturnBuffer;\r | |
106 | }\r | |
107 | \r | |
108 | /**\r | |
109 | Copy data from MMIO region to system memory by using 32-bit access.\r | |
110 | \r | |
111 | Copy data from MMIO region specified by starting address StartAddress \r | |
112 | to system memory specified by Buffer by using 32-bit access. The total \r | |
113 | number of byte to be copied is specified by Length. Buffer is returned.\r | |
114 | \r | |
115 | If StartAddress is not aligned on a 32-bit boundary, then ASSERT().\r | |
116 | \r | |
117 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT(). \r | |
118 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
119 | \r | |
120 | If Length is not aligned on a 32-bit boundary, then ASSERT().\r | |
121 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r | |
122 | \r | |
123 | @param StartAddress Starting address for the MMIO region to be copied from.\r | |
124 | @param Length Size in bytes of the copy.\r | |
125 | @param Buffer Pointer to a system memory buffer receiving the data read.\r | |
126 | \r | |
127 | @return Buffer\r | |
128 | \r | |
129 | **/\r | |
130 | UINT32 *\r | |
131 | EFIAPI\r | |
132 | MmioReadBuffer32 (\r | |
133 | IN UINTN StartAddress,\r | |
134 | IN UINTN Length,\r | |
135 | OUT UINT32 *Buffer\r | |
136 | )\r | |
137 | {\r | |
138 | UINT32 *ReturnBuffer;\r | |
139 | \r | |
140 | ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);\r | |
141 | \r | |
142 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
143 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
144 | \r | |
145 | ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);\r | |
146 | ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);\r | |
147 | \r | |
148 | ReturnBuffer = Buffer;\r | |
149 | \r | |
150 | while (Length > 0) {\r | |
151 | *(Buffer++) = MmioRead32 (StartAddress);\r | |
152 | StartAddress += sizeof (UINT32);\r | |
153 | Length -= sizeof (UINT32);\r | |
154 | }\r | |
155 | \r | |
156 | return ReturnBuffer;\r | |
157 | }\r | |
158 | \r | |
159 | /**\r | |
160 | Copy data from MMIO region to system memory by using 64-bit access.\r | |
161 | \r | |
162 | Copy data from MMIO region specified by starting address StartAddress \r | |
163 | to system memory specified by Buffer by using 64-bit access. The total \r | |
164 | number of byte to be copied is specified by Length. Buffer is returned.\r | |
165 | \r | |
166 | If StartAddress is not aligned on a 64-bit boundary, then ASSERT().\r | |
167 | \r | |
168 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT(). \r | |
169 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
170 | \r | |
171 | If Length is not aligned on a 64-bit boundary, then ASSERT().\r | |
172 | If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r | |
173 | \r | |
174 | @param StartAddress Starting address for the MMIO region to be copied from.\r | |
175 | @param Length Size in bytes of the copy.\r | |
176 | @param Buffer Pointer to a system memory buffer receiving the data read.\r | |
177 | \r | |
178 | @return Buffer\r | |
179 | \r | |
180 | **/\r | |
181 | UINT64 *\r | |
182 | EFIAPI\r | |
183 | MmioReadBuffer64 (\r | |
184 | IN UINTN StartAddress,\r | |
185 | IN UINTN Length,\r | |
186 | OUT UINT64 *Buffer\r | |
187 | )\r | |
188 | {\r | |
189 | UINT64 *ReturnBuffer;\r | |
190 | \r | |
191 | ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);\r | |
192 | \r | |
193 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
194 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
195 | \r | |
196 | ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);\r | |
197 | ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);\r | |
198 | \r | |
199 | ReturnBuffer = Buffer;\r | |
200 | \r | |
201 | while (Length > 0) {\r | |
202 | *(Buffer++) = MmioRead64 (StartAddress);\r | |
203 | StartAddress += sizeof (UINT64);\r | |
204 | Length -= sizeof (UINT64);\r | |
205 | }\r | |
206 | \r | |
207 | return ReturnBuffer;\r | |
208 | }\r | |
209 | \r | |
210 | \r | |
211 | /**\r | |
212 | Copy data from system memory to MMIO region by using 8-bit access.\r | |
213 | \r | |
214 | Copy data from system memory specified by Buffer to MMIO region specified \r | |
215 | by starting address StartAddress by using 8-bit access. The total number \r | |
216 | of byte to be copied is specified by Length. Buffer is returned.\r | |
217 | \r | |
218 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT(). \r | |
219 | If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r | |
220 | \r | |
221 | \r | |
222 | @param StartAddress Starting address for the MMIO region to be copied to.\r | |
223 | @param Length Size in bytes of the copy.\r | |
224 | @param Buffer Pointer to a system memory buffer containing the data to write.\r | |
225 | \r | |
226 | @return Buffer\r | |
227 | \r | |
228 | **/\r | |
229 | UINT8 *\r | |
230 | EFIAPI\r | |
231 | MmioWriteBuffer8 (\r | |
232 | IN UINTN StartAddress,\r | |
233 | IN UINTN Length,\r | |
234 | IN CONST UINT8 *Buffer\r | |
235 | )\r | |
236 | {\r | |
237 | VOID* ReturnBuffer;\r | |
238 | \r | |
239 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
240 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
241 | \r | |
242 | ReturnBuffer = (UINT8 *) Buffer;\r | |
243 | \r | |
244 | while (Length-- > 0) {\r | |
245 | MmioWrite8 (StartAddress++, *(Buffer++));\r | |
246 | }\r | |
247 | \r | |
248 | return ReturnBuffer;\r | |
249 | \r | |
250 | }\r | |
251 | \r | |
252 | /**\r | |
253 | Copy data from system memory to MMIO region by using 16-bit access.\r | |
254 | \r | |
255 | Copy data from system memory specified by Buffer to MMIO region specified \r | |
256 | by starting address StartAddress by using 16-bit access. The total number \r | |
257 | of byte to be copied is specified by Length. Buffer is returned.\r | |
258 | \r | |
259 | If StartAddress is not aligned on a 16-bit boundary, then ASSERT().\r | |
260 | \r | |
261 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT(). \r | |
262 | If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r | |
263 | \r | |
264 | If Length is not aligned on a 16-bit boundary, then ASSERT().\r | |
265 | \r | |
266 | If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r | |
267 | \r | |
268 | @param StartAddress Starting address for the MMIO region to be copied to.\r | |
269 | @param Length Size in bytes of the copy.\r | |
270 | @param Buffer Pointer to a system memory buffer containing the data to write.\r | |
271 | \r | |
272 | @return Buffer\r | |
273 | \r | |
274 | **/\r | |
275 | UINT16 *\r | |
276 | EFIAPI\r | |
277 | MmioWriteBuffer16 (\r | |
278 | IN UINTN StartAddress,\r | |
279 | IN UINTN Length,\r | |
280 | IN CONST UINT16 *Buffer\r | |
281 | )\r | |
282 | {\r | |
283 | UINT16 *ReturnBuffer;\r | |
284 | \r | |
285 | ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);\r | |
286 | \r | |
287 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
288 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
289 | \r | |
290 | ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);\r | |
291 | ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);\r | |
292 | \r | |
293 | ReturnBuffer = (UINT16 *) Buffer;\r | |
294 | \r | |
295 | while (Length > 0) {\r | |
296 | MmioWrite16 (StartAddress, *(Buffer++));\r | |
297 | \r | |
298 | StartAddress += sizeof (UINT16);\r | |
299 | Length -= sizeof (UINT16);\r | |
300 | }\r | |
301 | \r | |
302 | return ReturnBuffer;\r | |
303 | }\r | |
304 | \r | |
305 | \r | |
306 | /**\r | |
307 | Copy data from system memory to MMIO region by using 32-bit access.\r | |
308 | \r | |
309 | Copy data from system memory specified by Buffer to MMIO region specified \r | |
310 | by starting address StartAddress by using 32-bit access. The total number \r | |
311 | of byte to be copied is specified by Length. Buffer is returned.\r | |
312 | \r | |
313 | If StartAddress is not aligned on a 32-bit boundary, then ASSERT().\r | |
314 | \r | |
315 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT(). \r | |
316 | If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r | |
317 | \r | |
318 | If Length is not aligned on a 32-bit boundary, then ASSERT().\r | |
319 | \r | |
320 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r | |
321 | \r | |
322 | @param StartAddress Starting address for the MMIO region to be copied to.\r | |
323 | @param Length Size in bytes of the copy.\r | |
324 | @param Buffer Pointer to a system memory buffer containing the data to write.\r | |
325 | \r | |
326 | @return Buffer\r | |
327 | \r | |
328 | **/\r | |
329 | UINT32 *\r | |
330 | EFIAPI\r | |
331 | MmioWriteBuffer32 (\r | |
332 | IN UINTN StartAddress,\r | |
333 | IN UINTN Length,\r | |
334 | IN CONST UINT32 *Buffer\r | |
335 | )\r | |
336 | {\r | |
337 | UINT32 *ReturnBuffer;\r | |
338 | \r | |
339 | ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);\r | |
340 | \r | |
341 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
342 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
343 | \r | |
344 | ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);\r | |
345 | ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);\r | |
346 | \r | |
347 | ReturnBuffer = (UINT32 *) Buffer;\r | |
348 | \r | |
349 | while (Length > 0) {\r | |
350 | MmioWrite32 (StartAddress, *(Buffer++));\r | |
351 | \r | |
352 | StartAddress += sizeof (UINT32);\r | |
353 | Length -= sizeof (UINT32);\r | |
354 | }\r | |
355 | \r | |
356 | return ReturnBuffer;\r | |
357 | }\r | |
358 | \r | |
359 | /**\r | |
360 | Copy data from system memory to MMIO region by using 64-bit access.\r | |
361 | \r | |
362 | Copy data from system memory specified by Buffer to MMIO region specified \r | |
363 | by starting address StartAddress by using 64-bit access. The total number \r | |
364 | of byte to be copied is specified by Length. Buffer is returned.\r | |
365 | \r | |
366 | If StartAddress is not aligned on a 64-bit boundary, then ASSERT().\r | |
367 | \r | |
368 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT(). \r | |
369 | If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r | |
370 | \r | |
371 | If Length is not aligned on a 64-bit boundary, then ASSERT().\r | |
372 | \r | |
373 | If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r | |
374 | \r | |
375 | @param StartAddress Starting address for the MMIO region to be copied to.\r | |
376 | @param Length Size in bytes of the copy.\r | |
377 | @param Buffer Pointer to a system memory buffer containing the data to write.\r | |
378 | \r | |
379 | @return Buffer\r | |
380 | \r | |
381 | **/\r | |
382 | UINT64 *\r | |
383 | EFIAPI\r | |
384 | MmioWriteBuffer64 (\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 |