[edk2] [PATCH 05/12] OvmfPkg QemuFlash: Make QemuFlashDetected external

Jordan Justen posted 12 patches 7 years, 7 months ago
[edk2] [PATCH 05/12] OvmfPkg QemuFlash: Make QemuFlashDetected external
Posted by Jordan Justen 7 years, 7 months ago
QemuFlashDetected is also changed to not use global variables.

Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
---
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c | 29 +++++++++++++++++-----
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h | 14 +++++++++++
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
index 68388048f3..90e7810733 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
@@ -16,6 +16,7 @@
 #include <Library/BaseMemoryLib.h>
 #include <Library/DebugLib.h>
 #include <Library/PcdLib.h>
+#include <Uefi.h>
 
 #include "QemuFlash.h"
 
@@ -37,12 +38,25 @@ STATIC UINTN       mFdBlockCount = 0;
 
 STATIC
 volatile UINT8*
+QemuFlashPtrEx (
+  UINT8     *FlashBase,
+  UINTN     BlockSize,
+  IN        EFI_LBA                             Lba,
+  IN        UINTN                               Offset
+  )
+{
+  return FlashBase + ((UINTN)Lba * BlockSize) + Offset;
+}
+
+
+STATIC
+volatile UINT8*
 QemuFlashPtr (
   IN        EFI_LBA                             Lba,
   IN        UINTN                               Offset
   )
 {
-  return mFlashBase + ((UINTN)Lba * mFdBlockSize) + Offset;
+  return QemuFlashPtrEx (mFlashBase, mFdBlockSize, Lba, Offset);
 }
 
 
@@ -53,7 +67,6 @@ QemuFlashPtr (
   @retval TRUE    The QEMU flash device is present.
 
 **/
-STATIC
 BOOLEAN
 QemuFlashDetected (
   VOID
@@ -66,11 +79,15 @@ QemuFlashDetected (
   UINT8 OriginalUint8;
   UINT8 ProbeUint8;
 
+  UINT8 *FlashBase = (UINT8*)(UINTN) PcdGet32 (PcdOvmfFdBaseAddress);
+  UINTN BlockSize = PcdGet32 (PcdOvmfFirmwareBlockSize);
+  ASSERT(PcdGet32 (PcdOvmfFirmwareFdSize) % BlockSize == 0);
+
   FlashDetected = FALSE;
-  Ptr = QemuFlashPtr (0, 0);
+  Ptr = QemuFlashPtrEx (FlashBase, BlockSize, 0, 0);
 
-  for (Offset = 0; Offset < mFdBlockSize; Offset++) {
-    Ptr = QemuFlashPtr (0, Offset);
+  for (Offset = 0; Offset < BlockSize; Offset++) {
+    Ptr = QemuFlashPtrEx (FlashBase, BlockSize, 0, Offset);
     ProbeUint8 = *Ptr;
     if (ProbeUint8 != CLEAR_STATUS_CMD &&
         ProbeUint8 != READ_STATUS_CMD &&
@@ -79,7 +96,7 @@ QemuFlashDetected (
     }
   }
 
-  if (Offset >= mFdBlockSize) {
+  if (Offset >= BlockSize) {
     DEBUG ((EFI_D_INFO, "QEMU Flash: Failed to find probe location\n"));
     return FALSE;
   }
diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h
index 4bd971b0d1..04f89364ab 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h
@@ -19,6 +19,20 @@
 extern UINT8 *mFlashBase;
 
 /**
+  Detect if QEMU Flash is available and writable
+
+  Note: This function does not use read or write global variables.
+
+  @retval TRUE  Flash is writable
+
+**/
+BOOLEAN
+QemuFlashDetected (
+  VOID
+  );
+
+
+/**
   Read from QEMU Flash
 
   @param[in] Lba      The starting logical block index to read from.
-- 
2.11.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel