]>
Commit | Line | Data |
---|---|---|
b7c5912a | 1 | /** @file\r |
2 | I/O Library MMIO Buffer Functions.\r | |
3 | \r | |
9095d37b | 4 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r |
19388d29 | 5 | This program and the accompanying materials\r |
b7c5912a | 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 | |
2fc59a00 | 8 | http://opensource.org/licenses/bsd-license.php.\r |
b7c5912a | 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 | |
b7c5912a | 13 | **/\r |
14 | \r | |
b7c5912a | 15 | #include "SmmCpuIoLibInternal.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 | |
2fc59a00 | 28 | @param StartAddress The starting address for the MMIO region to be copied from.\r |
29 | @param Length The size in bytes of the copy.\r | |
30 | @param Buffer The pointer to a system memory buffer receiving the data read.\r | |
b7c5912a | 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 | |
9095d37b | 70 | \r |
b7c5912a | 71 | If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r |
72 | \r | |
2fc59a00 | 73 | @param StartAddress The starting address for the MMIO region to be copied from.\r |
74 | @param Length The size in bytes of the copy.\r | |
75 | @param Buffer The pointer to a system memory buffer receiving the data read.\r | |
b7c5912a | 76 | \r |
77 | @return Buffer\r | |
78 | \r | |
79 | **/\r | |
80 | UINT16 *\r | |
81 | EFIAPI\r | |
82 | MmioReadBuffer16 (\r | |
83 | IN UINTN StartAddress,\r | |
84 | IN UINTN Length,\r | |
85 | OUT UINT16 *Buffer\r | |
86 | )\r | |
87 | {\r | |
88 | UINT16 *ReturnBuffer;\r | |
89 | \r | |
90 | ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);\r | |
91 | \r | |
92 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
93 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
94 | \r | |
95 | ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);\r | |
96 | ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);\r | |
97 | \r | |
98 | ReturnBuffer = Buffer;\r | |
99 | \r | |
100 | while (Length > 0) {\r | |
101 | *(Buffer++) = MmioRead16 (StartAddress);\r | |
102 | StartAddress += sizeof (UINT16);\r | |
103 | Length -= sizeof (UINT16);\r | |
104 | }\r | |
105 | \r | |
106 | return ReturnBuffer;\r | |
107 | }\r | |
108 | \r | |
109 | /**\r | |
110 | Copy data from MMIO region to system memory by using 32-bit access.\r | |
111 | \r | |
112 | Copy data from MMIO region specified by starting address StartAddress\r | |
113 | to system memory specified by Buffer by using 32-bit access. The total\r | |
114 | number of byte to be copied is specified by Length. Buffer is returned.\r | |
115 | \r | |
116 | If StartAddress is not aligned on a 32-bit boundary, then ASSERT().\r | |
117 | \r | |
118 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r | |
119 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
120 | \r | |
121 | If Length is not aligned on a 32-bit boundary, then ASSERT().\r | |
122 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r | |
123 | \r | |
2fc59a00 | 124 | @param StartAddress The starting address for the MMIO region to be copied from.\r |
125 | @param Length The size in bytes of the copy.\r | |
126 | @param Buffer The pointer to a system memory buffer receiving the data read.\r | |
b7c5912a | 127 | \r |
128 | @return Buffer\r | |
129 | \r | |
130 | **/\r | |
131 | UINT32 *\r | |
132 | EFIAPI\r | |
133 | MmioReadBuffer32 (\r | |
134 | IN UINTN StartAddress,\r | |
135 | IN UINTN Length,\r | |
136 | OUT UINT32 *Buffer\r | |
137 | )\r | |
138 | {\r | |
139 | UINT32 *ReturnBuffer;\r | |
140 | \r | |
141 | ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);\r | |
142 | \r | |
143 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
144 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
145 | \r | |
146 | ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);\r | |
147 | ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);\r | |
148 | \r | |
149 | ReturnBuffer = Buffer;\r | |
150 | \r | |
151 | while (Length > 0) {\r | |
152 | *(Buffer++) = MmioRead32 (StartAddress);\r | |
153 | StartAddress += sizeof (UINT32);\r | |
154 | Length -= sizeof (UINT32);\r | |
155 | }\r | |
156 | \r | |
157 | return ReturnBuffer;\r | |
158 | }\r | |
159 | \r | |
160 | /**\r | |
161 | Copy data from MMIO region to system memory by using 64-bit access.\r | |
162 | \r | |
163 | Copy data from MMIO region specified by starting address StartAddress\r | |
164 | to system memory specified by Buffer by using 64-bit access. The total\r | |
165 | number of byte to be copied is specified by Length. Buffer is returned.\r | |
166 | \r | |
167 | If StartAddress is not aligned on a 64-bit boundary, then ASSERT().\r | |
168 | \r | |
169 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r | |
170 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
171 | \r | |
172 | If Length is not aligned on a 64-bit boundary, then ASSERT().\r | |
9095d37b | 173 | \r |
b7c5912a | 174 | If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r |
175 | \r | |
2fc59a00 | 176 | @param StartAddress The starting address for the MMIO region to be copied from.\r |
177 | @param Length The size in bytes of the copy.\r | |
178 | @param Buffer The pointer to a system memory buffer receiving the data read.\r | |
b7c5912a | 179 | \r |
180 | @return Buffer\r | |
181 | \r | |
182 | **/\r | |
183 | UINT64 *\r | |
184 | EFIAPI\r | |
185 | MmioReadBuffer64 (\r | |
186 | IN UINTN StartAddress,\r | |
187 | IN UINTN Length,\r | |
188 | OUT UINT64 *Buffer\r | |
189 | )\r | |
190 | {\r | |
191 | UINT64 *ReturnBuffer;\r | |
192 | \r | |
193 | ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);\r | |
194 | \r | |
195 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
196 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
197 | \r | |
198 | ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);\r | |
199 | ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);\r | |
200 | \r | |
201 | ReturnBuffer = Buffer;\r | |
202 | \r | |
203 | while (Length > 0) {\r | |
204 | *(Buffer++) = MmioRead64 (StartAddress);\r | |
205 | StartAddress += sizeof (UINT64);\r | |
206 | Length -= sizeof (UINT64);\r | |
207 | }\r | |
208 | \r | |
209 | return ReturnBuffer;\r | |
210 | }\r | |
211 | \r | |
212 | \r | |
213 | /**\r | |
214 | Copy data from system memory to MMIO region by using 8-bit access.\r | |
215 | \r | |
216 | Copy data from system memory specified by Buffer to MMIO region specified\r | |
217 | by starting address StartAddress by using 8-bit access. The total number\r | |
218 | of byte to be copied is specified by Length. Buffer is returned.\r | |
219 | \r | |
220 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r | |
221 | If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r | |
222 | \r | |
223 | \r | |
2fc59a00 | 224 | @param StartAddress The starting address for the MMIO region to be copied to.\r |
58380e9c | 225 | @param Length The size in bytes of the copy.\r |
9095d37b | 226 | @param Buffer The pointer to a system memory buffer containing the\r |
58380e9c | 227 | data to write.\r |
b7c5912a | 228 | \r |
229 | @return Buffer\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-- > 0) {\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. Buffer 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 | |
2fc59a00 | 271 | @param StartAddress The starting address for the MMIO region to be copied to.\r |
58380e9c | 272 | @param Length The size in bytes of the copy.\r |
9095d37b | 273 | @param Buffer The pointer to a system memory buffer containing the\r |
58380e9c | 274 | data to write.\r |
b7c5912a | 275 | \r |
276 | @return Buffer\r | |
277 | \r | |
278 | **/\r | |
279 | UINT16 *\r | |
280 | EFIAPI\r | |
281 | MmioWriteBuffer16 (\r | |
282 | IN UINTN StartAddress,\r | |
283 | IN UINTN Length,\r | |
284 | IN CONST UINT16 *Buffer\r | |
285 | )\r | |
286 | {\r | |
287 | UINT16 *ReturnBuffer;\r | |
288 | \r | |
289 | ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);\r | |
290 | \r | |
291 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
292 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
293 | \r | |
294 | ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);\r | |
295 | ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);\r | |
296 | \r | |
297 | ReturnBuffer = (UINT16 *) Buffer;\r | |
298 | \r | |
299 | while (Length > 0) {\r | |
300 | MmioWrite16 (StartAddress, *(Buffer++));\r | |
301 | \r | |
302 | StartAddress += sizeof (UINT16);\r | |
303 | Length -= sizeof (UINT16);\r | |
304 | }\r | |
305 | \r | |
306 | return ReturnBuffer;\r | |
307 | }\r | |
308 | \r | |
309 | \r | |
310 | /**\r | |
311 | Copy data from system memory to MMIO region by using 32-bit access.\r | |
312 | \r | |
313 | Copy data from system memory specified by Buffer to MMIO region specified\r | |
314 | by starting address StartAddress by using 32-bit access. The total number\r | |
315 | of byte to be copied is specified by Length. Buffer is returned.\r | |
316 | \r | |
317 | If StartAddress is not aligned on a 32-bit boundary, then ASSERT().\r | |
318 | \r | |
319 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r | |
320 | If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r | |
321 | \r | |
322 | If Length is not aligned on a 32-bit boundary, then ASSERT().\r | |
323 | \r | |
324 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r | |
325 | \r | |
2fc59a00 | 326 | @param StartAddress The starting address for the MMIO region to be copied to.\r |
58380e9c | 327 | @param Length The size in bytes of the copy.\r |
9095d37b | 328 | @param Buffer The pointer to a system memory buffer containing the\r |
58380e9c | 329 | data to write.\r |
b7c5912a | 330 | \r |
331 | @return Buffer\r | |
332 | \r | |
333 | **/\r | |
334 | UINT32 *\r | |
335 | EFIAPI\r | |
336 | MmioWriteBuffer32 (\r | |
337 | IN UINTN StartAddress,\r | |
338 | IN UINTN Length,\r | |
339 | IN CONST UINT32 *Buffer\r | |
340 | )\r | |
341 | {\r | |
342 | UINT32 *ReturnBuffer;\r | |
343 | \r | |
344 | ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);\r | |
345 | \r | |
346 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
347 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
348 | \r | |
349 | ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);\r | |
350 | ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);\r | |
351 | \r | |
352 | ReturnBuffer = (UINT32 *) Buffer;\r | |
353 | \r | |
354 | while (Length > 0) {\r | |
355 | MmioWrite32 (StartAddress, *(Buffer++));\r | |
356 | \r | |
357 | StartAddress += sizeof (UINT32);\r | |
358 | Length -= sizeof (UINT32);\r | |
359 | }\r | |
360 | \r | |
361 | return ReturnBuffer;\r | |
362 | }\r | |
363 | \r | |
364 | /**\r | |
365 | Copy data from system memory to MMIO region by using 64-bit access.\r | |
366 | \r | |
367 | Copy data from system memory specified by Buffer to MMIO region specified\r | |
368 | by starting address StartAddress by using 64-bit access. The total number\r | |
369 | of byte to be copied is specified by Length. Buffer is returned.\r | |
370 | \r | |
371 | If StartAddress is not aligned on a 64-bit boundary, then ASSERT().\r | |
372 | \r | |
373 | If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().\r | |
374 | If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().\r | |
375 | \r | |
376 | If Length is not aligned on a 64-bit boundary, then ASSERT().\r | |
377 | \r | |
378 | If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r | |
379 | \r | |
2fc59a00 | 380 | @param StartAddress The starting address for the MMIO region to be copied to.\r |
58380e9c | 381 | @param Length The size in bytes of the copy.\r |
9095d37b | 382 | @param Buffer The pointer to a system memory buffer containing the\r |
58380e9c | 383 | data to write.\r |
b7c5912a | 384 | \r |
385 | @return Buffer\r | |
386 | \r | |
387 | **/\r | |
388 | UINT64 *\r | |
389 | EFIAPI\r | |
390 | MmioWriteBuffer64 (\r | |
391 | IN UINTN StartAddress,\r | |
392 | IN UINTN Length,\r | |
393 | IN CONST UINT64 *Buffer\r | |
394 | )\r | |
395 | {\r | |
396 | UINT64 *ReturnBuffer;\r | |
397 | \r | |
398 | ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);\r | |
399 | \r | |
400 | ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));\r | |
401 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));\r | |
402 | \r | |
403 | ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);\r | |
404 | ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);\r | |
405 | \r | |
406 | ReturnBuffer = (UINT64 *) Buffer;\r | |
407 | \r | |
408 | while (Length > 0) {\r | |
409 | MmioWrite64 (StartAddress, *(Buffer++));\r | |
410 | \r | |
411 | StartAddress += sizeof (UINT64);\r | |
412 | Length -= sizeof (UINT64);\r | |
413 | }\r | |
414 | \r | |
415 | return ReturnBuffer;\r | |
416 | }\r | |
417 | \r |