From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web12.653.1666630905665637384 for ; Mon, 24 Oct 2022 10:01:45 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DdwuOJZH; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3140C611DD; Mon, 24 Oct 2022 17:01:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43C52C433C1; Mon, 24 Oct 2022 17:01:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666630904; bh=jt0RT8PIM44mumowwovtbKmZhsgJvQDhykanONSUYEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DdwuOJZHLE8xlBT7GrL7qg1yv5mXnkeZI4CmJ9h7C2UUq1d2A6z0lslc71qHiQhu9 ppb76sCtvgWQtku46DClbLIzlzumApAyed1PUI0P8D285XrzWAGBFx0xBvXFWzNTLX o5T3pOlnBJHNnzSW8fMxMZXBV+bM+p0V1G47HQFh4VcljyJX7AAqyYTDim+/ALOXFE V7rllqvUkpI/yojWSEl4f6FP0jajZhf/np/yFANQRoGtKmMiedM+uKhTmQcbHnhylD vRXqvDPZ4lW1xovSbYZmycfPROT5EmxgREhoS1IoXApGwgoEUKMfAhopXvh2HoQI1z /yMNfxdWwyn2w== From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Gerd Hoffmann , Sunil V L , Sami Mujawar , Leif Lindholm Subject: [PATCH 06/11] OvmfPkg/VirtNorFlashDxe: avoid array mode switch after each word write Date: Mon, 24 Oct 2022 19:01:17 +0200 Message-Id: <20221024170122.594577-7-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221024170122.594577-1-ardb@kernel.org> References: <20221024170122.594577-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 --- 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/VirtNorFlashD= xe/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);=0D }=0D =0D - // Put device back into Read Array mode=0D - SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);=0D -=0D return Status;=0D }=0D =0D @@ -286,8 +283,7 @@ NorFlashWriteBuffer ( =0D // The buffer was not available for writing=0D if (WaitForBuffer =3D=3D 0) {=0D - Status =3D EFI_DEVICE_ERROR;=0D - goto EXIT;=0D + return EFI_DEVICE_ERROR;=0D }=0D =0D // From now on we work in 32-bit words=0D @@ -337,10 +333,6 @@ NorFlashWriteBuffer ( SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS= _REGISTER);=0D }=0D =0D -EXIT:=0D - // Put device back into Read Array mode=0D - SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);=0D -=0D return Status;=0D }=0D =0D @@ -739,6 +731,8 @@ NorFlashWriteSingleBlock ( }=0D =0D TempStatus =3D NorFlashWriteSingleWord (Instance, WordAddr, WordToWr= ite);=0D + // Put device back into Read Array mode=0D + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY= );=0D if (EFI_ERROR (TempStatus)) {=0D return EFI_DEVICE_ERROR;=0D }=0D diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c b/OvmfPkg/VirtNorFla= shDxe/VirtNorFlashDxe.c index 2ceda226359c..f9a41f6aab0f 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c @@ -280,6 +280,9 @@ NorFlashWriteFullBlock ( }=0D =0D EXIT:=0D + // Put device back into Read Array mode=0D + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);=0D +=0D if (!EfiAtRuntime ()) {=0D // Interruptions can resume.=0D gBS->RestoreTPL (OriginalTPL);=0D --=20 2.35.1