public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb@kernel.org>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Sunil V L <sunilvl@ventanamicro.com>,
	Sami Mujawar <sami.mujawar@arm.com>,
	Leif Lindholm <quic_llindhol@quicinc.com>
Subject: [PATCH 06/11] OvmfPkg/VirtNorFlashDxe: avoid array mode switch after each word write
Date: Mon, 24 Oct 2022 19:01:17 +0200	[thread overview]
Message-ID: <20221024170122.594577-7-ardb@kernel.org> (raw)
In-Reply-To: <20221024170122.594577-1-ardb@kernel.org>

NorFlashWriteSingleWord() switches into programming mode and back into
array mode for every single word that it writes. Under KVM, this
involves tearing down the read-only memslot, and setting it up again,
which is costly and unnecessary.

Instead, move the array mode switch into the callers, and only make the
switch when the writing is done.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c    | 12 +++---------
 OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c |  3 +++
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c
index f41d9d372f49..0a5c5d48c738 100644
--- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c
+++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c
@@ -205,9 +205,6 @@ NorFlashWriteSingleWord (
     SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);
   }
 
-  // Put device back into Read Array mode
-  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
-
   return Status;
 }
 
@@ -286,8 +283,7 @@ NorFlashWriteBuffer (
 
   // The buffer was not available for writing
   if (WaitForBuffer == 0) {
-    Status = EFI_DEVICE_ERROR;
-    goto EXIT;
+    return EFI_DEVICE_ERROR;
   }
 
   // From now on we work in 32-bit words
@@ -337,10 +333,6 @@ NorFlashWriteBuffer (
     SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);
   }
 
-EXIT:
-  // Put device back into Read Array mode
-  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
-
   return Status;
 }
 
@@ -739,6 +731,8 @@ NorFlashWriteSingleBlock (
       }
 
       TempStatus = NorFlashWriteSingleWord (Instance, WordAddr, WordToWrite);
+      // Put device back into Read Array mode
+      SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
       if (EFI_ERROR (TempStatus)) {
         return EFI_DEVICE_ERROR;
       }
diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c
index 2ceda226359c..f9a41f6aab0f 100644
--- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c
+++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c
@@ -280,6 +280,9 @@ NorFlashWriteFullBlock (
   }
 
 EXIT:
+  // Put device back into Read Array mode
+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
+
   if (!EfiAtRuntime ()) {
     // Interruptions can resume.
     gBS->RestoreTPL (OriginalTPL);
-- 
2.35.1


  parent reply	other threads:[~2022-10-24 17:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-24 17:01 [PATCH 00/11] ArmVirtPkg: introduce VirtNorFlashDxe Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 01/11] OvmfPkg: clone NorFlashPlatformLib into VirtNorFlashPlatformLib Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 02/11] OvmfPkg/VirtNorFlashDxe: clone ArmPlatformPkg's NOR flash driver Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 03/11] OvmfPkg/VirtNorFlashDxe: remove CheckBlockLocked feature Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 04/11] OvmfPkg/VirtNorFlashDxe: remove disk I/O protocol implementation Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 05/11] OvmfPkg/VirtNorFlashDxe: drop block " Ard Biesheuvel
2022-10-24 17:01 ` Ard Biesheuvel [this message]
2022-10-24 17:01 ` [PATCH 07/11] OvmfPkg/VirtNorFlashDxe: avoid switching between modes in a tight loop Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 08/11] OvmfPkg/VirtNorFlashDxe: use EFI_MEMORY_WC and drop AlignedCopyMem() Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 09/11] ArmVirtPkg/ArmVirtQemu: migrate to OVMF's VirtNorFlashDxe Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 10/11] ArmVirtPkg/ArmVirtKvmTool: Migrate " Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 11/11] ArmPlatformPkg: Retire NorFlashDxe driver Ard Biesheuvel
2022-10-25 16:32   ` Leif Lindholm
2022-10-27  4:47 ` [PATCH 00/11] ArmVirtPkg: introduce VirtNorFlashDxe Sunil V L
2022-10-27 16:56   ` Ard Biesheuvel

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=20221024170122.594577-7-ardb@kernel.org \
    --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