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