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