From: Laszlo Ersek <lersek@redhat.com>
To: edk2-devel-01 <edk2-devel@lists.01.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH 4/5] ArmVirtPkg/QemuFwCfgLib: use DMA for QemuFwCfgWriteBytes() if available
Date: Fri, 27 Jan 2017 12:29:41 +0100 [thread overview]
Message-ID: <20170127112942.19212-5-lersek@redhat.com> (raw)
In-Reply-To: <20170127112942.19212-1-lersek@redhat.com>
We use the "InternalQemuFwCfgReadBytes" static function pointer to
dispatch the reading of fw_cfg bytes between MMIO and DMA. This pointer is
initialized to MMIO, and we set it to DMA in the library constructor if
DMA is available.
Unlike the above, we write fw_cfg bytes only with MMIO at the moment.
Extend the write functionality so that it follows the read pattern:
- introduce the new function typedef WRITE_BYTES_FUNCTION,
- extract the current (MMIO-only) write internals from
QemuFwCfgWriteBytes() to MmioWriteBytes(),
- provide a DMA-based implementation in DmaWriteBytes() -- a thin wrapper
around DmaTransferBytes(),
- set the new static function pointer "InternalQemuFwCfgWriteBytes"
according to the DMA feature provided by QEMU,
- In QemuFwCfgWriteBytes(), call the best available method through
"InternalQemuFwCfgWriteBytes".
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>
---
ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c | 60 ++++++++++++++++++--
1 file changed, 54 insertions(+), 6 deletions(-)
diff --git a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
index bd0f34720eec..56db908f5c91 100644
--- a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
+++ b/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
@@ -42,16 +42,32 @@ VOID (EFIAPI READ_BYTES_FUNCTION) (
IN VOID *Buffer OPTIONAL
);
+/**
+ Writes bytes from a buffer to firmware configuration
+
+ @param[in] Size Size in bytes to write
+ @param[in] Buffer Buffer to transfer data from (OPTIONAL if Size is 0)
+
+**/
+typedef
+VOID (EFIAPI WRITE_BYTES_FUNCTION) (
+ IN UINTN Size,
+ IN VOID *Buffer OPTIONAL
+ );
+
//
// Forward declaration of the two implementations we have.
//
STATIC READ_BYTES_FUNCTION MmioReadBytes;
+STATIC WRITE_BYTES_FUNCTION MmioWriteBytes;
STATIC READ_BYTES_FUNCTION DmaReadBytes;
+STATIC WRITE_BYTES_FUNCTION DmaWriteBytes;
//
-// This points to the one we detect at runtime.
+// These correspond to the implementation we detect at runtime.
//
STATIC READ_BYTES_FUNCTION *InternalQemuFwCfgReadBytes = MmioReadBytes;
+STATIC WRITE_BYTES_FUNCTION *InternalQemuFwCfgWriteBytes = MmioWriteBytes;
/**
@@ -166,6 +182,7 @@ QemuFwCfgInitialize (
if ((Features & FW_CFG_F_DMA) != 0) {
mFwCfgDmaAddress = FwCfgDmaAddress;
InternalQemuFwCfgReadBytes = DmaReadBytes;
+ InternalQemuFwCfgWriteBytes = DmaWriteBytes;
}
}
} else {
@@ -358,6 +375,41 @@ QemuFwCfgReadBytes (
}
}
+
+/**
+ Slow WRITE_BYTES_FUNCTION.
+**/
+STATIC
+VOID
+EFIAPI
+MmioWriteBytes (
+ IN UINTN Size,
+ IN VOID *Buffer OPTIONAL
+ )
+{
+ UINTN Idx;
+
+ for (Idx = 0; Idx < Size; ++Idx) {
+ MmioWrite8 (mFwCfgDataAddress, ((UINT8 *)Buffer)[Idx]);
+ }
+}
+
+
+/**
+ Fast WRITE_BYTES_FUNCTION.
+**/
+STATIC
+VOID
+EFIAPI
+DmaWriteBytes (
+ IN UINTN Size,
+ IN VOID *Buffer OPTIONAL
+ )
+{
+ DmaTransferBytes (Size, Buffer, FW_CFG_DMA_CTL_WRITE);
+}
+
+
/**
Write firmware configuration bytes from a buffer
@@ -376,11 +428,7 @@ QemuFwCfgWriteBytes (
)
{
if (QemuFwCfgIsAvailable ()) {
- UINTN Idx;
-
- for (Idx = 0; Idx < Size; ++Idx) {
- MmioWrite8 (mFwCfgDataAddress, ((UINT8 *)Buffer)[Idx]);
- }
+ InternalQemuFwCfgWriteBytes (Size, Buffer);
}
}
--
2.9.3
next prev parent reply other threads:[~2017-01-27 11:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-27 11:29 [PATCH 0/5] OvmfPkg, ArmVirtPkg: QemuFwCfgLib: partial rewrite of fw_cfg files Laszlo Ersek
2017-01-27 11:29 ` [PATCH 1/5] OvmfPkg/QemuFwCfgLib: generalize InternalQemuFwCfgDmaBytes() to SKIP op Laszlo Ersek
2017-01-27 11:29 ` [PATCH 2/5] OvmfPkg/QemuFwCfgLib: add QemuFwCfgSkipBytes() Laszlo Ersek
2017-01-27 11:29 ` [PATCH 3/5] ArmVirtPkg/QemuFwCfgLib: extract generic DmaTransferBytes() function Laszlo Ersek
2017-01-27 11:29 ` Laszlo Ersek [this message]
2017-01-27 11:29 ` [PATCH 5/5] ArmVirtPkg/QemuFwCfgLib: implement QemuFwCfgSkipBytes() API Laszlo Ersek
2017-01-27 18:25 ` [PATCH 0/5] OvmfPkg, ArmVirtPkg: QemuFwCfgLib: partial rewrite of fw_cfg files Ard Biesheuvel
2017-01-30 23:07 ` Jordan Justen
2017-01-30 23:18 ` Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170127112942.19212-5-lersek@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox