ArmVirtPkg/QemuFwCfgLib: extract generic DmaTransferBytes() function

The DmaReadBytes() function that we currently use only for reading --
through the InternalQemuFwCfgReadBytes function pointer, in case the DMA
interface is available -- is suitable with minimal changes for two more
operations provided by the DMA interface, WRITE and SKIP. Expose the
Control parameter in the function prototype, rename the function to
DmaTransferBytes(), and rebase DmaReadBytes() to it.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=359
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
This commit is contained in:
Laszlo Ersek 2017-01-27 06:56:19 +01:00
parent fcca9f67fb
commit 4175356fb4
1 changed files with 36 additions and 6 deletions

View File

@ -250,26 +250,41 @@ MmioReadBytes (
/**
Fast READ_BYTES_FUNCTION.
Transfer an array of bytes, or skip a number of bytes, using the DMA
interface.
@param[in] Size Size in bytes to transfer or skip.
@param[in,out] Buffer Buffer to read data into or write data from. Ignored,
and may be NULL, if Size is zero, or Control is
FW_CFG_DMA_CTL_SKIP.
@param[in] Control One of the following:
FW_CFG_DMA_CTL_WRITE - write to fw_cfg from Buffer.
FW_CFG_DMA_CTL_READ - read from fw_cfg into Buffer.
FW_CFG_DMA_CTL_SKIP - skip bytes in fw_cfg.
**/
STATIC
VOID
EFIAPI
DmaReadBytes (
IN UINTN Size,
IN VOID *Buffer OPTIONAL
DmaTransferBytes (
IN UINTN Size,
IN OUT VOID *Buffer OPTIONAL,
IN UINT32 Control
)
{
volatile FW_CFG_DMA_ACCESS Access;
UINT32 Status;
ASSERT (Control == FW_CFG_DMA_CTL_WRITE || Control == FW_CFG_DMA_CTL_READ ||
Control == FW_CFG_DMA_CTL_SKIP);
if (Size == 0) {
return;
}
ASSERT (Size <= MAX_UINT32);
Access.Control = SwapBytes32 (FW_CFG_DMA_CTL_READ);
Access.Control = SwapBytes32 (Control);
Access.Length = SwapBytes32 ((UINT32)Size);
Access.Address = SwapBytes64 ((UINT64)(UINTN)Buffer);
@ -304,6 +319,21 @@ DmaReadBytes (
}
/**
Fast READ_BYTES_FUNCTION.
**/
STATIC
VOID
EFIAPI
DmaReadBytes (
IN UINTN Size,
IN VOID *Buffer OPTIONAL
)
{
DmaTransferBytes (Size, Buffer, FW_CFG_DMA_CTL_READ);
}
/**
Reads firmware configuration bytes into a buffer