From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7B56E81FB8 for ; Fri, 27 Jan 2017 03:29:51 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 199CF7FB69; Fri, 27 Jan 2017 11:29:52 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-16.ams2.redhat.com [10.36.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22D7D20E473; Fri, 27 Jan 2017 11:29:50 +0000 (UTC) From: Laszlo Ersek To: edk2-devel-01 Cc: Ard Biesheuvel Date: Fri, 27 Jan 2017 12:29:40 +0100 Message-Id: <20170127112942.19212-4-lersek@redhat.com> In-Reply-To: <20170127112942.19212-1-lersek@redhat.com> References: <20170127112942.19212-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 27 Jan 2017 11:29:52 +0000 (UTC) Subject: [PATCH 3/5] ArmVirtPkg/QemuFwCfgLib: extract generic DmaTransferBytes() function X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jan 2017 11:29:51 -0000 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 --- ArmVirtPkg/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 1b19893709fc..bd0f34720eec 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); @@ -305,6 +320,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 If called multiple times, then the data read will continue at the offset of -- 2.9.3