From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by mx.groups.io with SMTP id smtpd.web12.5675.1665655186955983275 for ; Thu, 13 Oct 2022 03:00:08 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=kZOEl9e0; spf=pass (domain: ventanamicro.com, ip: 209.85.216.46, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pj1-f46.google.com with SMTP id a5-20020a17090aa50500b002008eeb040eso5267934pjq.1 for ; Thu, 13 Oct 2022 03:00:08 -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=kZOEl9e0+INyGyLg0l3Qnjdb5LUjeB1AboGQRJvqRWjC9SVGzUjxLuGE3r0aGz6dqk uOPj5JY8GsBJMArIlF5nIWcwMqD5YFndDsIlrAbU4ImLFQYJnH/PRhUI/OAZviUxUCEx mrDdXuwg/E8PJCuHCEwPqN/YlbRj/219NKQ5jqvVdLzKzdQoUcotGNGpjLV/G8n9cCnO 42rhZ444Kvzb3mYfF7kuCaasApwIW9C3EdtAB59kL/+zGQQMa5ZRTpYYeBa/RmO5s364 cT3hVG4MxMFlFphIEGTIUosGg2WCPgAcYx1vrvHdj0+8jM/dXLEif6DkRoVGWsamJtC+ FnWA== 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=f7aRUYIaqdruTEQ2L+/fEsJU7h/Sc8+w7J5RntJ5XIogxjSz+8Kq0TSL/HadozDjOs ES7TJTCxV8SooylO2OuDnrXx64bNtc1djPk3m/pC1NnbSz2FyLRQwgWSbMP5j4yOb/Va dB0MA1hKd16GFOwAtT3OXMH6whwcMkJHvnzAj+e2esq8XQn1KMa/CP77seSeZG4GRkX+ kLqm9MFixLZRBVVm3oKoIJjlrk9QkEiBDrvcLzZdkRRU6q88g4AITFzJNKW1C5lkI02g 5alkQIhEL9NB4JsxaVvL0YvPuemyBPYkWRraTXGp56b0Uzor/1m/uqzv3tZ6bSN6+ZtZ xz9w== X-Gm-Message-State: ACrzQf1305f3p4umfH34gPGUwCNifKhrkDBY6BBRi5dFRJlXhQZaDQJV SnBSGmYHu8eVzdUTvhxnwSWOxvXWuys4zQ== X-Google-Smtp-Source: AMsMyM5TvRseLjY++wBEXNovpmxgBir94F0naZ86CYJP742hulhit+FQGCiH5XD/OXA+c6rM4G62sA== X-Received: by 2002:a17:90b:1b4f:b0:20d:6ddd:9ef6 with SMTP id nv15-20020a17090b1b4f00b0020d6ddd9ef6mr10125478pjb.200.1665655207886; Thu, 13 Oct 2022 03:00:07 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.03.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 03:00:07 -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 V3 30/34] OvmfPkg/NorFlashDxe: Avoid switching to array mode during writes Date: Thu, 13 Oct 2022 15:28:25 +0530 Message-Id: <20221013095829.1454581-31-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-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