From nobody Tue Feb 10 01:50:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95093+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95093+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665571597; cv=none; d=zohomail.com; s=zohoarc; b=E8XBALUskghJWz9FnpkZ6+7Msu3XmjqPmf9lkTlwUF5nVbdle29L6pzwqo3bwxZg+AjufBNpHLTErgtRWEQ8RgH2d9Mm14MnA46kn1R4L9z8Eo+c6Wy8fOVQYHh60RttUm+M863KAOyV9LI36HL2CNqRZHhcMBbPbfEkmy1nQqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665571597; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=czvitVpuk0HIEc9ZQ7YBXZE8Vdwk+sFSwDSCsv3r9Fg=; b=N70un3cp6yIyAIzLW0HyjcwsbNKSCVAl6XjwNlfDb3RpgQNbDea6Px7UOLXn4y+jspcyxjpo/UmljWvrqsxVzpOP3uMOtISr0UQc5QE3l4ilwrwqIGNNdUNOd5YiHZTZeGMvvK/0EhAZ/ilWSkpYiqdfnJFND9z0RyELLRFnWNs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95093+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665571597050942.0502944281964; Wed, 12 Oct 2022 03:46:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1kOWYY1788612xwUcC5pFVVw; Wed, 12 Oct 2022 03:46:36 -0700 X-Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mx.groups.io with SMTP id smtpd.web12.18913.1665571596043056315 for ; Wed, 12 Oct 2022 03:46:36 -0700 X-Received: by mail-pf1-f181.google.com with SMTP id 67so16100858pfz.12 for ; Wed, 12 Oct 2022 03:46:36 -0700 (PDT) X-Gm-Message-State: 1mZCZlc8B5lU2KxQW2lrrPmwx1787277AA= X-Google-Smtp-Source: AMsMyM7wGHT/WavOTLjtiNRWVFukYESDiJVe770XAk+lwF6TkJdzOXpl8fGZXAm/0X3zY/EQthrWlQ== X-Received: by 2002:a62:5a86:0:b0:563:553d:878e with SMTP id o128-20020a625a86000000b00563553d878emr16445534pfb.73.1665571595315; Wed, 12 Oct 2022 03:46:35 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id z4-20020aa79e44000000b0054223a0185asm10812221pfq.161.2022.10.12.03.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 03:46:34 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V2 29/33] OvmfPkg/NorFlashDxe: Avoid switching to array mode during writes Date: Wed, 12 Oct 2022 16:14:52 +0530 Message-Id: <20221012104456.1393376-30-sunilvl@ventanamicro.com> In-Reply-To: <20221012104456.1393376-1-sunilvl@ventanamicro.com> References: <20221012104456.1393376-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665571596; bh=2QZ0NsjDlbaqVQTHWZmJm8jEdMww9/GM53bfAocEVLA=; h=Cc:Date:From:Reply-To:Subject:To; b=A2mGxgbMOhvZ0AfW0oPwY8Uq9HjMxn5zrAwF6qgBSbM31aS7MID2bKAUCZRA/iR8br1 TbnKDndxk4chIwJbKCqN6YvAXHbZge1a8nov6foKXTWs3MzbiOHVxzg1yDlXD1RiKXooe d01sPaOLzHABERAOK/NvZZbU5otr8A80jYQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665571598901100003 Content-Type: text/plain; charset="utf-8" Switching to array mode (i.e., ROM memory mode rather than NOR flash programming mode) is rather costly when running under KVM emulation, as it involves setting up the read-only memslot in the hypervisor's stage 2 page tables. So let's avoid jumping between modes unnecessarily, and only switch back to array mode when we are done writing to flash. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Ard Biesheuvel --- OvmfPkg/Drivers/NorFlashDxe/NorFlash.c | 9 +++------ OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c | 3 +++ OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlash.c b/OvmfPkg/Drivers/NorFl= ashDxe/NorFlash.c index c2a6aa281578..cdc6b5da8bfb 100644 --- a/OvmfPkg/Drivers/NorFlashDxe/NorFlash.c +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlash.c @@ -205,9 +205,6 @@ NorFlashWriteSingleWord ( SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS= _REGISTER); } =20 - // Put device back into Read Array mode - SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); - return Status; } =20 @@ -338,9 +335,6 @@ NorFlashWriteBuffer ( } =20 EXIT: - // Put device back into Read Array mode - SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); - return Status; } =20 @@ -750,6 +744,9 @@ NorFlashWriteSingleBlock ( } =20 TempStatus =3D NorFlashWriteSingleWord (Instance, WordAddr, WordToWr= ite); + // 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/Drivers/NorFlashDxe/NorFlashDxe.c b/OvmfPkg/Drivers/No= rFlashDxe/NorFlashDxe.c index f7b92de21a57..862a8e621fd0 100644 --- a/OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c @@ -316,6 +316,9 @@ NorFlashWriteFullBlock ( } =20 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); diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c b/OvmfPkg/D= rivers/NorFlashDxe/NorFlashStandaloneMm.c index b72ad97b0b55..f6dec84176d4 100644 --- a/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c @@ -270,6 +270,9 @@ NorFlashWriteFullBlock ( } =20 EXIT: + // Put device back into Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); + if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed = at address 0x%08x. Exit Status =3D \"%r\".\n", WordAddress, Status)); } --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95093): https://edk2.groups.io/g/devel/message/95093 Mute This Topic: https://groups.io/mt/94278113/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-