From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by mx.groups.io with SMTP id smtpd.web08.9721.1665766206462408920 for ; Fri, 14 Oct 2022 09:50:06 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=YUmx7Z46; spf=pass (domain: ventanamicro.com, ip: 209.85.214.176, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pl1-f176.google.com with SMTP id f23so5262352plr.6 for ; Fri, 14 Oct 2022 09:50:06 -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=WdBamOewOM7gcY/oYRO51bgkgMqSBNk2BM73eOO9Wa0=; b=YUmx7Z46gooq8ysmSd+OxZDl1Dy8/dO5CFRHAzNXI6DbDTpKJzKfC/tR/RAwmXZwUh o30ZjirL4TNPexj5/tmN7Ko6Gfwq5Z9XY0k/PhZtCr19ixEfb/SpNrpg2I89Mx8ysY1/ LsPrzhHbQ4QXBPHey8kara+uxdVgkTEnt4LFU6lug1jA+TYn7ZsQg8Crd0z+S+DJ6gKp RFcmD+FDfKS0MFNAMT+dO8iafRnGw3D5pyyU6KOCHvUVl+nGaYV0z0xltFDBvxe13I8z oB6mI+s/vnK9wqqXCVH//tL3tLBkHYSP029ilkdRGqfYNszbfr3hFVNj+mNUEayFYzyK mCVA== 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=WdBamOewOM7gcY/oYRO51bgkgMqSBNk2BM73eOO9Wa0=; b=i1aoE8PL2eWQhHZD6933X4hAyWvO4Hzkcr5GfhTODW5Lndnpw6tVThQkBYqRDvuLwD WWQLonDo5D3qtz0AcZG5ZX6ZJYQuBwGHtievOZTwvH0Gx+pPplMI7xEAO9H9awpoYZWS 8d303CmWG3kaJlfcPuGkxB6flYjd53HueWhKO4vA67Jl38Uf2P77JOmmGIvO+7Tca+Jt uScleFnPk2PdfHTOlnAxMK+1bcFj5IIyfrO2sOzx1ZCDavlGfpNXeAAZ3NkSmBBsfSsk 7rbwcu+e7/6mR/Zj2+bnTM5DfGiPc4YJJYokPfiYtceUBzcxArTQbYre3iRqpOdCSRnR 5a0Q== X-Gm-Message-State: ACrzQf1Fbyb/bB1/CE+kmhU/iJ+F9Nt82L68c/eaG5XDBo19Lv19VA6W viDdMpn9usoLWki4FrJY1UIJt6uQmaRE/g== X-Google-Smtp-Source: AMsMyM61Ku6lgqhWLPz6YgqZsP9S3qkVaPkT+L3rRxJFeX68irXZwnbeerH19GXG0FOWETXpm4bMKg== X-Received: by 2002:a17:902:dad2:b0:17f:7439:20f2 with SMTP id q18-20020a170902dad200b0017f743920f2mr6060131plx.29.1665766205730; Fri, 14 Oct 2022 09:50:05 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id f3-20020a62db03000000b0056265011136sm1963368pfg.112.2022.10.14.09.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 09:50:05 -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 V4 30/34] OvmfPkg/NorFlashDxe: Avoid switching to array mode during writes Date: Fri, 14 Oct 2022 22:18:32 +0530 Message-Id: <20221014164836.1513036-31-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221014164836.1513036-1-sunilvl@ventanamicro.com> References: <20221014164836.1513036-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.38.0