IoLibMmioBuffer.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
4632N/A/** @file
4632N/A I/O Library MMIO Buffer Functions.
4632N/A
4632N/A Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
4632N/A This program and the accompanying materials
4632N/A are licensed and made available under the terms and conditions of the BSD License
4632N/A which accompanies this distribution. The full text of the license may be found at
4632N/A http://opensource.org/licenses/bsd-license.php.
4632N/A
4632N/A THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
4632N/A WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
4632N/A
4632N/A**/
4632N/A
4632N/A#include "DxeIoLibEsalInternal.h"
4632N/A
4632N/A/**
4632N/A Copy data from MMIO region to system memory by using 8-bit access.
4632N/A
4632N/A Copy data from MMIO region specified by starting address StartAddress
4632N/A to system memory specified by Buffer by using 8-bit access. The total
4632N/A number of byte to be copied is specified by Length. Buffer is returned.
4632N/A
4632N/A If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
4632N/A If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4632N/A
4632N/A
4632N/A @param StartAddress Starting address for the MMIO region to be copied from.
4632N/A @param Length Size in bytes of the copy.
4632N/A @param Buffer Pointer to a system memory buffer receiving the data read.
4632N/A
4632N/A @return Buffer
4632N/A
4632N/A**/
4632N/AUINT8 *
4632N/AEFIAPI
4632N/AMmioReadBuffer8 (
4632N/A IN UINTN StartAddress,
4632N/A IN UINTN Length,
4632N/A OUT UINT8 *Buffer
4632N/A )
4632N/A{
4632N/A UINT8 *ReturnBuffer;
4632N/A
4632N/A ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
4632N/A ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
4632N/A
4632N/A ReturnBuffer = Buffer;
4632N/A
4632N/A while (Length-- > 0) {
4632N/A *(Buffer++) = MmioRead8 (StartAddress++);
4632N/A }
4632N/A
4632N/A return ReturnBuffer;
4632N/A}
4632N/A
4632N/A/**
4632N/A Copy data from MMIO region to system memory by using 16-bit access.
4632N/A
4632N/A Copy data from MMIO region specified by starting address StartAddress
4632N/A to system memory specified by Buffer by using 16-bit access. The total
4632N/A number of byte to be copied is specified by Length. Buffer is returned.
4632N/A
4632N/A If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
4632N/A
4632N/A If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
4632N/A If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4632N/A
4632N/A If Length is not aligned on a 16-bit boundary, then ASSERT().
4632N/A If Buffer is not aligned on a 16-bit boundary, then ASSERT().
4632N/A
4632N/A @param StartAddress Starting address for the MMIO region to be copied from.
4632N/A @param Length Size in bytes of the copy.
4632N/A @param Buffer Pointer to a system memory buffer receiving the data read.
4632N/A
4632N/A @return Buffer
4632N/A
4632N/A**/
4632N/AUINT16 *
4632N/AEFIAPI
5333N/AMmioReadBuffer16 (
4632N/A IN UINTN StartAddress,
5333N/A IN UINTN Length,
4632N/A OUT UINT16 *Buffer
4632N/A )
4632N/A{
4632N/A UINT16 *ReturnBuffer;
4632N/A
4632N/A ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);
4632N/A
4632N/A ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
4632N/A ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
4632N/A
4632N/A ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);
4632N/A ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);
4632N/A
4632N/A ReturnBuffer = Buffer;
4632N/A
4632N/A while (Length > 0) {
4632N/A *(Buffer++) = MmioRead16 (StartAddress);
4632N/A StartAddress += sizeof (UINT16);
4632N/A Length -= sizeof (UINT16);
5555N/A }
6055N/A
5555N/A return ReturnBuffer;
5555N/A}
5555N/A
5555N/A/**
4632N/A Copy data from MMIO region to system memory by using 32-bit access.
5555N/A
4632N/A Copy data from MMIO region specified by starting address StartAddress
4632N/A to system memory specified by Buffer by using 32-bit access. The total
4632N/A number of byte to be copied is specified by Length. Buffer is returned.
4632N/A
4632N/A If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
4632N/A
4632N/A If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
4632N/A If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4632N/A
4632N/A If Length is not aligned on a 32-bit boundary, then ASSERT().
4632N/A If Buffer is not aligned on a 32-bit boundary, then ASSERT().
4632N/A
4632N/A @param StartAddress Starting address for the MMIO region to be copied from.
4632N/A @param Length Size in bytes of the copy.
4632N/A @param Buffer Pointer to a system memory buffer receiving the data read.
4632N/A
5555N/A @return Buffer
5555N/A
4632N/A**/
4632N/AUINT32 *
4632N/AEFIAPI
5555N/AMmioReadBuffer32 (
4632N/A IN UINTN StartAddress,
4632N/A IN UINTN Length,
4632N/A OUT UINT32 *Buffer
)
{
UINT32 *ReturnBuffer;
ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);
ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);
ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);
ReturnBuffer = Buffer;
while (Length > 0) {
*(Buffer++) = MmioRead32 (StartAddress);
StartAddress += sizeof (UINT32);
Length -= sizeof (UINT32);
}
return ReturnBuffer;
}
/**
Copy data from MMIO region to system memory by using 64-bit access.
Copy data from MMIO region specified by starting address StartAddress
to system memory specified by Buffer by using 64-bit access. The total
number of byte to be copied is specified by Length. Buffer is returned.
If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
If Length is not aligned on a 64-bit boundary, then ASSERT().
If Buffer is not aligned on a 64-bit boundary, then ASSERT().
@param StartAddress Starting address for the MMIO region to be copied from.
@param Length Size in bytes of the copy.
@param Buffer Pointer to a system memory buffer receiving the data read.
@return Buffer
**/
UINT64 *
EFIAPI
MmioReadBuffer64 (
IN UINTN StartAddress,
IN UINTN Length,
OUT UINT64 *Buffer
)
{
UINT64 *ReturnBuffer;
ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);
ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);
ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);
ReturnBuffer = Buffer;
while (Length > 0) {
*(Buffer++) = MmioRead64 (StartAddress);
StartAddress += sizeof (UINT64);
Length -= sizeof (UINT64);
}
return ReturnBuffer;
}
/**
Copy data from system memory to MMIO region by using 8-bit access.
Copy data from system memory specified by Buffer to MMIO region specified
by starting address StartAddress by using 8-bit access. The total number
of byte to be copied is specified by Length. Buffer is returned.
If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
@param StartAddress Starting address for the MMIO region to be copied to.
@param Length Size in bytes of the copy.
@param Buffer Pointer to a system memory buffer containing the data to write.
@return Buffer
**/
UINT8 *
EFIAPI
MmioWriteBuffer8 (
IN UINTN StartAddress,
IN UINTN Length,
IN CONST UINT8 *Buffer
)
{
VOID* ReturnBuffer;
ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
ReturnBuffer = (UINT8 *) Buffer;
while (Length-- > 0) {
MmioWrite8 (StartAddress++, *(Buffer++));
}
return ReturnBuffer;
}
/**
Copy data from system memory to MMIO region by using 16-bit access.
Copy data from system memory specified by Buffer to MMIO region specified
by starting address StartAddress by using 16-bit access. The total number
of byte to be copied is specified by Length. Buffer is returned.
If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
If Length is not aligned on a 16-bit boundary, then ASSERT().
If Buffer is not aligned on a 16-bit boundary, then ASSERT().
@param StartAddress Starting address for the MMIO region to be copied to.
@param Length Size in bytes of the copy.
@param Buffer Pointer to a system memory buffer containing the data to write.
@return Buffer
**/
UINT16 *
EFIAPI
MmioWriteBuffer16 (
IN UINTN StartAddress,
IN UINTN Length,
IN CONST UINT16 *Buffer
)
{
UINT16 *ReturnBuffer;
ASSERT ((StartAddress & (sizeof (UINT16) - 1)) == 0);
ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
ASSERT ((Length & (sizeof (UINT16) - 1)) == 0);
ASSERT (((UINTN) Buffer & (sizeof (UINT16) - 1)) == 0);
ReturnBuffer = (UINT16 *) Buffer;
while (Length > 0) {
MmioWrite16 (StartAddress, *(Buffer++));
StartAddress += sizeof (UINT16);
Length -= sizeof (UINT16);
}
return ReturnBuffer;
}
/**
Copy data from system memory to MMIO region by using 32-bit access.
Copy data from system memory specified by Buffer to MMIO region specified
by starting address StartAddress by using 32-bit access. The total number
of byte to be copied is specified by Length. Buffer is returned.
If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
If Length is not aligned on a 32-bit boundary, then ASSERT().
If Buffer is not aligned on a 32-bit boundary, then ASSERT().
@param StartAddress Starting address for the MMIO region to be copied to.
@param Length Size in bytes of the copy.
@param Buffer Pointer to a system memory buffer containing the data to write.
@return Buffer
**/
UINT32 *
EFIAPI
MmioWriteBuffer32 (
IN UINTN StartAddress,
IN UINTN Length,
IN CONST UINT32 *Buffer
)
{
UINT32 *ReturnBuffer;
ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);
ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);
ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);
ReturnBuffer = (UINT32 *) Buffer;
while (Length > 0) {
MmioWrite32 (StartAddress, *(Buffer++));
StartAddress += sizeof (UINT32);
Length -= sizeof (UINT32);
}
return ReturnBuffer;
}
/**
Copy data from system memory to MMIO region by using 64-bit access.
Copy data from system memory specified by Buffer to MMIO region specified
by starting address StartAddress by using 64-bit access. The total number
of byte to be copied is specified by Length. Buffer is returned.
If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
If Length is not aligned on a 64-bit boundary, then ASSERT().
If Buffer is not aligned on a 64-bit boundary, then ASSERT().
@param StartAddress Starting address for the MMIO region to be copied to.
@param Length Size in bytes of the copy.
@param Buffer Pointer to a system memory buffer containing the data to write.
@return Buffer
**/
UINT64 *
EFIAPI
MmioWriteBuffer64 (
IN UINTN StartAddress,
IN UINTN Length,
IN CONST UINT64 *Buffer
)
{
UINT64 *ReturnBuffer;
ASSERT ((StartAddress & (sizeof (UINT64) - 1)) == 0);
ASSERT ((Length - 1) <= (MAX_ADDRESS - StartAddress));
ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN) Buffer));
ASSERT ((Length & (sizeof (UINT64) - 1)) == 0);
ASSERT (((UINTN) Buffer & (sizeof (UINT64) - 1)) == 0);
ReturnBuffer = (UINT64 *) Buffer;
while (Length > 0) {
MmioWrite64 (StartAddress, *(Buffer++));
StartAddress += sizeof (UINT64);
Length -= sizeof (UINT64);
}
return ReturnBuffer;
}