From 4175356fb4bfe89415677aed8fb4e6928ced2ff1 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Fri, 27 Jan 2017 06:56:19 +0100 Subject: [PATCH] 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 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=359 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Reviewed-by: Ard Biesheuvel Reviewed-by: Jordan Justen --- .../Library/QemuFwCfgLib/QemuFwCfgLib.c | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c index 1b19893709..bd0f34720e 100644 --- a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c +++ b/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c @@ -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 -- 2.39.2