From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=He9d39Q0; spf=pass (domain: ventanamicro.com, ip: 209.85.210.181, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pf1-f181.google.com with SMTP id 67so16100858pfz.12 for ; Wed, 12 Oct 2022 03:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wt+3a6mTjr49YpBJ3TVOB5YB7BWdZxS3uS1TGQDdf0s=; b=He9d39Q0U3egI5T6EFObNwo5UjOfJeD7eHYSqMfHLgfIfQ2oAaVfC4qiSwn/bFDzk2 19A+9WuTWoXpQ5uUpRLFgFLdLVVXPZzklBgTGebalz7DB2Hr6m4pzbjnlYAjfaFQmfOZ OuuVm4QHzruXTq7l0S4YyF/fO4sjAFhK9oIeD8PAlrCQex5Dv4KGLuSlViHQId2DguKf WbeZ4rC8dEWd6FWtXZFllcHiYfZVX6TRvceFPTT88YJ+T05qY7QKiXZhxwH8fKxSuA7z CsGI+3PfmbQE95oPAt8vCh0rBDqUjs2+FGDW0uJNsQgqFeUbHETEFuPsYShemKeX9/cX pyxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wt+3a6mTjr49YpBJ3TVOB5YB7BWdZxS3uS1TGQDdf0s=; b=R/OlZgfV8z0YzY1/shK2sUOxzi0pZWQqVCRZD8xQsK+8IymO/dsEovBOHMWEu19di6 0MaHtJRiY+JdPAWzr130hW/fdrr8w8Av5dgRfoEY6euIaWGPutRyWBYVJz/vw0bJZwkl 3dh2WhIg8FKO4R1MulMhCs+obqhdab1zjZcUn7nGKzAs/4YqL3n4G+tOQ0n0iYeEAWZs k7xNjqzEE7rnzim1UqGUqf3ccL8nde8Va95eZdtW/jwT5JBJ4d+Qh/NcEApmtriiNdpW d4qwbZGthYOx4YoZQ7yrDbl+g6nO3iawIr3i7ALtimbvxJavKlwM83S6ekhSGfR0CLhd r+nA== X-Gm-Message-State: ACrzQf3AootE5fB4iiqlXHNPbpOMy2aRtGreUdPnj+UdYnXjdDGxDIkC luSoqSw4Dz5X8CISu+NlW7sWmu/Dp/U/Ug== 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) Return-Path: 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-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> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221012104456.1393376-1-sunilvl@ventanamicro.com> References: <20221012104456.1393376-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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/NorFlashDxe/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); } - // Put device back into Read Array mode - SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); - return Status; } @@ -338,9 +335,6 @@ NorFlashWriteBuffer ( } EXIT: - // Put device back into Read Array mode - SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); - return Status; } @@ -750,6 +744,9 @@ 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/Drivers/NorFlashDxe/NorFlashDxe.c b/OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c index f7b92de21a57..862a8e621fd0 100644 --- a/OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c @@ -316,6 +316,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); diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c b/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c index b72ad97b0b55..f6dec84176d4 100644 --- a/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c @@ -270,6 +270,9 @@ NorFlashWriteFullBlock ( } 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 = \"%r\".\n", WordAddress, Status)); } -- 2.25.1