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