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