public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: edk2-devel-01 <edk2-devel@lists.01.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Subject: [PATCH 2/5] OvmfPkg/QemuFwCfgLib: add QemuFwCfgSkipBytes()
Date: Fri, 27 Jan 2017 12:29:39 +0100	[thread overview]
Message-ID: <20170127112942.19212-3-lersek@redhat.com> (raw)
In-Reply-To: <20170127112942.19212-1-lersek@redhat.com>

Introduce the new public API QemuFwCfgSkipBytes(), for advancing over
bytes in the selected firmware configuration item without transferring
data between the item and the caller.

When the DMA interface is available (the common case), the operation is
instantaneous. As a fallback, provide a loop of chunked reads into a small
stack-allocated scratch buffer.

This patch enables OvmfPkg/QemuFwCfgLib to overwrite part of a writeable
fw_cfg file, which will be particularly useful for the upcoming
QEMU_LOADER_WRITE_POINTER command in OvmfPkg/AcpiPlatformDxe.

Cc: Jordan Justen <jordan.l.justen@intel.com>
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>
---
 OvmfPkg/Include/Library/QemuFwCfgLib.h      | 16 +++++++
 OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c | 44 ++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/OvmfPkg/Include/Library/QemuFwCfgLib.h b/OvmfPkg/Include/Library/QemuFwCfgLib.h
index 3e017d53a97e..41c3817470a2 100644
--- a/OvmfPkg/Include/Library/QemuFwCfgLib.h
+++ b/OvmfPkg/Include/Library/QemuFwCfgLib.h
@@ -159,6 +159,22 @@ QemuFwCfgWriteBytes (
 
 
 /**
+  Skip bytes in the firmware configuration item.
+
+  Increase the offset of the firmware configuration item without transferring
+  bytes between the item and a caller-provided buffer. Subsequent read, write
+  or skip operations will commence at the increased offset.
+
+  @param[in] Size  Number of bytes to skip.
+**/
+VOID
+EFIAPI
+QemuFwCfgSkipBytes (
+  IN UINTN                  Size
+  );
+
+
+/**
   Reads a UINT8 firmware configuration value
 
   @return    Value of Firmware Configuration item read
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
index 6b6b2c7726e1..7744873217fe 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
@@ -193,6 +193,50 @@ QemuFwCfgWriteBytes (
 
 
 /**
+  Skip bytes in the firmware configuration item.
+
+  Increase the offset of the firmware configuration item without transferring
+  bytes between the item and a caller-provided buffer. Subsequent read, write
+  or skip operations will commence at the increased offset.
+
+  @param[in] Size  Number of bytes to skip.
+**/
+VOID
+EFIAPI
+QemuFwCfgSkipBytes (
+  IN UINTN                  Size
+  )
+{
+  UINTN ChunkSize;
+  UINT8 SkipBuffer[256];
+
+  if (!InternalQemuFwCfgIsAvailable ()) {
+    return;
+  }
+
+  if (InternalQemuFwCfgDmaIsAvailable () && Size <= MAX_UINT32) {
+    InternalQemuFwCfgDmaBytes ((UINT32)Size, NULL, FW_CFG_DMA_CTL_SKIP);
+    return;
+  }
+
+  //
+  // Emulate the skip by reading data in chunks, and throwing it away. The
+  // implementation below is suitable even for phases where RAM or dynamic
+  // allocation is not available or appropriate. It also doesn't affect the
+  // static data footprint for client modules. Large skips are not expected,
+  // therefore this fallback is not performance critical. The size of
+  // SkipBuffer is thought not to exert a large pressure on the stack in any
+  // phase.
+  //
+  while (Size > 0) {
+    ChunkSize = MIN (Size, sizeof SkipBuffer);
+    IoReadFifo8 (0x511, ChunkSize, SkipBuffer);
+    Size -= ChunkSize;
+  }
+}
+
+
+/**
   Reads a UINT8 firmware configuration value
 
   @return    Value of Firmware Configuration item read
-- 
2.9.3




  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 ` Laszlo Ersek [this message]
2017-01-27 11:29 ` [PATCH 3/5] ArmVirtPkg/QemuFwCfgLib: extract generic DmaTransferBytes() function Laszlo Ersek
2017-01-27 11:29 ` [PATCH 4/5] ArmVirtPkg/QemuFwCfgLib: use DMA for QemuFwCfgWriteBytes() if available Laszlo Ersek
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-3-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