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