From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (EUR04-VI1-obe.outbound.protection.outlook.com [40.107.8.81]) by mx.groups.io with SMTP id smtpd.web10.31644.1650902719593569070 for ; Mon, 25 Apr 2022 09:05:20 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=zw+XndDX; spf=pass (domain: arm.com, ip: 40.107.8.81, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=79IPgvYWM6fCQlhNIZP3Z3BiIE6WcYpL3dto9g+ABdo=; b=zw+XndDXO4hxvAY8o5BreMAeHJ2am8b73tQ76rnOofXsTnPJY5Cb1MkU385Jvr6MWlCTbxQ81TslUfki4bVvFkpHLZ+xrBw160bDVvausoe7EsknPqIJD3sQVGYwXeDyOLKsAvqGg4r5VwG4gCIb+s+4eaR+6cIrBa2jXH0rGD0= Received: from DB7PR05CA0013.eurprd05.prod.outlook.com (2603:10a6:10:36::26) by DB8PR08MB5417.eurprd08.prod.outlook.com (2603:10a6:10:117::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14; Mon, 25 Apr 2022 16:05:15 +0000 Received: from DB5EUR03FT046.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:36:cafe::c7) by DB7PR05CA0013.outlook.office365.com (2603:10a6:10:36::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.21 via Frontend Transport; Mon, 25 Apr 2022 16:05:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT046.mail.protection.outlook.com (10.152.21.230) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Mon, 25 Apr 2022 16:05:15 +0000 Received: ("Tessian outbound 9613c00560a5:v118"); Mon, 25 Apr 2022 16:05:15 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e966404a4cfc6cbf X-CR-MTA-TID: 64aa7808 Received: from 70e3ac630c3f.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 842A7519-5EEF-466D-BEEC-AE9A34B1E4D9.1; Mon, 25 Apr 2022 16:05:08 +0000 Received: from EUR02-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 70e3ac630c3f.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 25 Apr 2022 16:05:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QzSEnalYIpmIS4hQVJTT0Gf9IGzbPQsPkkcbFxcSndK4x7ZNHH4hq4YdfMmV95FLCQq6cysB2Zn0caJ5/QPja1a2IbKA1d4BXt7UsqaCuZztYYD42LME54q3UbWImQMN6tdvE4dqmSkLWoCQu9QdQk3u1xOoU/I5fSjpEQRpJzHFGnMPfa0Xr4AeKTMV1duafdPBeed7HFZIOzmMvIII9WF/Y/FGRzQdcGAmnvnbKpMVFrynFwUFvkDYPSwu3Hz3cS9D+ptjZw5BcA9QnUiSulK5wmJMBecc+Dk0jcz8B8+kWByfaKZAZjEJnbOr9uP0G2E5TfY10AVFlOvlbUwrSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=79IPgvYWM6fCQlhNIZP3Z3BiIE6WcYpL3dto9g+ABdo=; b=hIaTVtmL/aIJtyYJ5widhWYghGi78WIUSGb3zsXROZdHRDu8RKmximc6IlJ5rggUvXKwCwAzy48aI7tKg+rpsOyLI0VyKuRPksof0T2OBnacD++fOyXAVIekjsN/U/kfaxAQ05h3rx6LqQ21R2SDy41WIU6Y4sX1qAp7Q2TVbw+ytik1aAgF0pVZwF9LpxqHW2+8/4o7pN+4xpxHG79mS8coS2jOjQcMin8R8K/P/TkJDIySDcBTbc0B011wcMfm1/v+QcQpTTdlAswotLOyvjmHJeG7SRxRKlgc4gdqcnM0q1t6fsO8Mfq2JF+HIO+IUst1rLWeRmhfDERYKS1njA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=79IPgvYWM6fCQlhNIZP3Z3BiIE6WcYpL3dto9g+ABdo=; b=zw+XndDXO4hxvAY8o5BreMAeHJ2am8b73tQ76rnOofXsTnPJY5Cb1MkU385Jvr6MWlCTbxQ81TslUfki4bVvFkpHLZ+xrBw160bDVvausoe7EsknPqIJD3sQVGYwXeDyOLKsAvqGg4r5VwG4gCIb+s+4eaR+6cIrBa2jXH0rGD0= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) by HE1PR0802MB2153.eurprd08.prod.outlook.com (2603:10a6:3:c2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Mon, 25 Apr 2022 16:05:05 +0000 Received: from AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::fd9a:40d3:976a:5a95]) by AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::fd9a:40d3:976a:5a95%4]) with mapi id 15.20.5186.021; Mon, 25 Apr 2022 16:05:05 +0000 Message-ID: <45a37a8e-0fd7-45a4-5eec-dbbc0d42ba33@arm.com> Date: Mon, 25 Apr 2022 17:05:05 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [edk2-devel] [PATCH v4 2/8] MdeModulePkg/VariableFlashInfoLib: Add initial library To: devel@edk2.groups.io, mikuback@linux.microsoft.com Cc: Jian J Wang , Hao A Wu , Liming Gao , nd@arm.com References: <20220412162940.4978-1-mikuback@linux.microsoft.com> <20220412162940.4978-3-mikuback@linux.microsoft.com> From: "Sami Mujawar" In-Reply-To: <20220412162940.4978-3-mikuback@linux.microsoft.com> X-ClientProxiedBy: LO2P265CA0277.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a1::25) To AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: c61555a2-cb18-4493-130b-08da26d562a3 X-MS-TrafficTypeDiagnostic: HE1PR0802MB2153:EE_|DB5EUR03FT046:EE_|DB8PR08MB5417:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: N1YguWa763o05LKQc5fttQM3d8pAXwaO7XNOL55M2Of3jby5Sz0wi8gwJ2aEDoopattiAxLQ7dAtusaKt5axc80zsdNAEnxNqFaGUKde33i5i88HDkGsQ8HUkcL5aOIm94LnqjhsGXCb2fWvc4loKnsbgwqDDBjO2kl202kOwHo53Isgd7/+whtMX0a8AtHktDSVAe/pVjlYAAHnH9orPPGZUBraACM/5YSkrLVUKQAbUHpZrb/GWm/jkPRn3SsQePMQI4JXDQNkmiaYBLLxa7bcZUTOsicZp0+IQY7KJnKiR8Q3Z9mgSVVhdTwEUjvsApVK3JJkfdt2GDRSr2zuAbhd6rsX5qgKixvjFIFYWOtLEh+w1jHHlhvMXgjLBx8tnjHOLcuBjCVkO8o0SQ4EzEoajyKc/2x8ZZvUVH96+EZ5TZUzdNEeNbsSmf6P1tGEPLIM3p79mpMJ6nYArw0yps9trQ2tyCZGKhoL463dC9NHRvmZd2roF9BpZshFblqP2me5fp6sFGcH2fh5sQ6vmEQx8pm5dTaka4iZt60SRcFxJd1XmBgg9PbLQFdw7QMd7ta/UJe+jfzV5uySF5RDLQPXVymASGGA04ZVgYyuHRP90ulYb2sFqS87T1WGJtNzjRsZ58fB1+Z7tlY9cyyJne/Kqk0arwc2OLKAtDdoHCG+Kqc+N9iLFdPSwb9gcm0sL8LD4AiXzlU5YmHVqZg+AH2GOzUtnhYuoEbz6BqhxT/1DpZXppZ40OqthSYQpUM/fx4VEMbmgsgHbAkwbarCBi+Uc9UdwD+iAVlFUhPM2px6OvogZntU1JSme5JKerTgA8zxs9Q5++yED5rAdhMlwg== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR08MB6806.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(8936002)(44832011)(83380400001)(31686004)(6512007)(26005)(86362001)(54906003)(316002)(5660300002)(45080400002)(36756003)(186003)(6506007)(53546011)(2616005)(60390400001)(30864003)(2906002)(38100700002)(31696002)(508600001)(6486002)(66946007)(8676002)(4326008)(66556008)(66476007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2153 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Return-Path: Sami.Mujawar@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT046.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: e1124906-1cfc-4a0e-2b15-08da26d55cf2 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nC/t8FQPMxH55xvbJMcGw/oBorawtxlKer0RGAU8Egsw0FFVdbI1CEd2r9Gz+TNr2OYMmZtHnLPgs4b1Pb4TjixRLTaqbKxYfgE/0+5lCSpTWpQ1wCuOpnTFZVCIBZW8ycBvCbZ0wpb4zPuGBHbviiSpKoaWNpHbI3zVq0seDpzf6bU1jGH1k/M/ga0UUe7oKqng2mhMNaobjWCVMqki8fmGw1HIMCG6KZz8MEzuUMyzDgnphae2Nuzf4IkO616X2/v5YLQoJ2PMu+6WD6knpGcxOQc+xy4IqSoonKqyGilyHedYhtuuAdbHBRO4fd/Hvy9eint4mQE8+aHo2ApFpMaNvdwZv01Uk2Z62DUQod1pFhi4UpAGUrWLkhCJtjEbLrX0aTkXWSlh0eWIxJxSc0Mw5lNbUyM2dkWoAJFrHHh/GPFg0QOP2xMmROuy18066uDqJYUPJnBc1njeQMuqvjIWPmHXzFfxJQLrABGi22xFvTl6EFItNhR92IjHEUkkwuWv+L/+iHZErj/oZ7Ezu6TrmIUckbjKVUFXSqyzrlS8JgJx4TeaCqHK9pJQ0Z9p/fggHfFlkjUeDqLaR2CMMWhgFSNA5rKIWBA4dMcrabuxq+A5FH6cT8LDL6sS2TfhN9wzW3x5GkNAPPF52IsC2wWOQd0aLJzMl4SRK0NTAksXYEjGXq8n9kICPtGc51ply5Yy87Ri57OL3K0BU9pGPTfS1ZmVAgMI9W10IJawvDiixCyQNs5PkaXkLpqiagu6m+A3N5R+ZFMFmiHGxHFfUBBJ4oABXSf+dU/0NokcBVM= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(8936002)(44832011)(31686004)(6512007)(83380400001)(26005)(54906003)(36860700001)(5660300002)(316002)(45080400002)(47076005)(336012)(186003)(36756003)(2616005)(6506007)(53546011)(60390400001)(2906002)(86362001)(82310400005)(30864003)(31696002)(6486002)(508600001)(356005)(40460700003)(8676002)(4326008)(70206006)(70586007)(81166007)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2022 16:05:15.1090 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c61555a2-cb18-4493-130b-08da26d562a3 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT046.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5417 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Michael, I have a minor suggestion marked inline as [SAMI]. Otherwise this patch looks good to me. Reviewed-by: Sami Mujawar Regards, Sami Mujawar On 12/04/2022 05:29 pm, Michael Kubacki via groups.io wrote: > From: Michael Kubacki > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479 > > Adds a new library class VariableFlashInfoLib that abstracts access > to variable flash information. The instance provided first attempts > to retrieve information from the Variable Flash Info HOB. If that > HOB is not present, it falls back to the PCDs defined in > MdeModulePkg. > > This fall back behavior provides backward compatibility for platforms > that only provide PCDs but also allows platforms that need to > dynamically provide the information using the Variable Flash Info HOB > to do so at runtime. > > Cc: Jian J Wang > Cc: Hao A Wu > Cc: Liming Gao > Signed-off-by: Michael Kubacki > --- > MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c | 178 ++++++++++++++++++++ > MdeModulePkg/Include/Library/VariableFlashInfoLib.h | 68 ++++++++ > MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf | 48 ++++++ > MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni | 12 ++ > MdeModulePkg/MdeModulePkg.dec | 4 + > MdeModulePkg/MdeModulePkg.dsc | 2 + > 6 files changed, 312 insertions(+) > > diff --git a/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c > new file mode 100644 > index 000000000000..a1db97bdf218 > --- /dev/null > +++ b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c > @@ -0,0 +1,178 @@ > +/** @file > + Variable Flash Information Library > + > + Copyright (c) Microsoft Corporation
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +/** > + Get the HOB that contains variable flash information. > + > + @param[out] VariableFlashInfo Pointer to a pointer to set to the variable flash information structure. > + > + @retval EFI_SUCCESS Variable flash information was found successfully. > + @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is NULL. > + @retval EFI_NOT_FOUND Variable flash information could not be found. > + > +**/ > +EFI_STATUS > +GetVariableFlashInfoFromHob ( > + OUT VARIABLE_FLASH_INFO **VariableFlashInfo > + ) [SAMI] Can this function be made STATIC, please? > +{ > + EFI_HOB_GUID_TYPE *GuidHob; > + > + if (VariableFlashInfo == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + GuidHob = GetFirstGuidHob (&gVariableFlashInfoHobGuid); > + if (GuidHob == NULL) { > + return EFI_NOT_FOUND; > + } > + > + *VariableFlashInfo = GET_GUID_HOB_DATA (GuidHob); > + > + // > + // Assert if more than one variable flash information HOB is present. > + // > + DEBUG_CODE ( > + if ((GetNextGuidHob (&gVariableFlashInfoHobGuid, GET_NEXT_HOB (GuidHob)) != NULL)) { > + DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information HOBs\n")); > + ASSERT (FALSE); > + } > + > + ); > + > + return EFI_SUCCESS; > +} > + > +/** > + Get the base address and size for the NV storage area used for UEFI variable storage. > + > + @param[out] BaseAddress The NV storage base address. > + @param[out] Length The NV storage length in bytes. > + > + @retval EFI_SUCCESS NV storage information was found successfully. > + @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL. > + > +**/ > +EFI_STATUS > +EFIAPI > +GetVariableFlashNvStorageInfo ( > + OUT EFI_PHYSICAL_ADDRESS *BaseAddress, > + OUT UINT64 *Length > + ) > +{ > + EFI_STATUS Status; > + VARIABLE_FLASH_INFO *VariableFlashInfo; > + > + if ((BaseAddress == NULL) || (Length == NULL)) { > + return EFI_INVALID_PARAMETER; > + } > + > + Status = GetVariableFlashInfoFromHob (&VariableFlashInfo); > + if (!EFI_ERROR (Status)) { > + *BaseAddress = VariableFlashInfo->NvVariableBaseAddress; > + *Length = VariableFlashInfo->NvVariableLength; > + } else { > + *BaseAddress = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ? > + PcdGet64 (PcdFlashNvStorageVariableBase64) : > + PcdGet32 (PcdFlashNvStorageVariableBase) > + ); > + *Length = (UINT64)PcdGet32 (PcdFlashNvStorageVariableSize); > + } > + > + return EFI_SUCCESS; > +} > + > +/** > + Get the base address and size for the fault tolerant write (FTW) spare > + area used for UEFI variable storage. > + > + @param[out] BaseAddress The FTW spare base address. > + @param[out] Length The FTW spare length in bytes. > + > + @retval EFI_SUCCESS FTW spare information was found successfully. > + @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL. > + @retval EFI_NOT_FOUND FTW spare information could not be found. > + > +**/ > +EFI_STATUS > +EFIAPI > +GetVariableFlashFtwSpareInfo ( > + OUT EFI_PHYSICAL_ADDRESS *BaseAddress, > + OUT UINT64 *Length > + ) > +{ > + EFI_STATUS Status; > + VARIABLE_FLASH_INFO *VariableFlashInfo; > + > + if ((BaseAddress == NULL) || (Length == NULL)) { > + return EFI_INVALID_PARAMETER; > + } > + > + Status = GetVariableFlashInfoFromHob (&VariableFlashInfo); > + if (!EFI_ERROR (Status)) { > + *BaseAddress = VariableFlashInfo->FtwSpareBaseAddress; > + *Length = VariableFlashInfo->FtwSpareLength; > + } else { > + *BaseAddress = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageFtwSpareBase64) != 0 ? > + PcdGet64 (PcdFlashNvStorageFtwSpareBase64) : > + PcdGet32 (PcdFlashNvStorageFtwSpareBase) > + ); > + *Length = (UINT64)PcdGet32 (PcdFlashNvStorageFtwSpareSize); > + } > + > + return EFI_SUCCESS; > +} > + > +/** > + Get the base address and size for the fault tolerant write (FTW) working > + area used for UEFI variable storage. > + > + @param[out] BaseAddress The FTW working area base address. > + @param[out] Length The FTW working area length in bytes. > + > + @retval EFI_SUCCESS FTW working information was found successfully. > + @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL. > + @retval EFI_NOT_FOUND FTW working information could not be found. > + > +**/ > +EFI_STATUS > +EFIAPI > +GetVariableFlashFtwWorkingInfo ( > + OUT EFI_PHYSICAL_ADDRESS *BaseAddress, > + OUT UINT64 *Length > + ) > +{ > + EFI_STATUS Status; > + VARIABLE_FLASH_INFO *VariableFlashInfo; > + > + if ((BaseAddress == NULL) || (Length == NULL)) { > + return EFI_INVALID_PARAMETER; > + } > + > + Status = GetVariableFlashInfoFromHob (&VariableFlashInfo); > + if (!EFI_ERROR (Status)) { > + *BaseAddress = VariableFlashInfo->FtwWorkingBaseAddress; > + *Length = VariableFlashInfo->FtwWorkingLength; > + } else { > + *BaseAddress = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) != 0 ? > + PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) : > + PcdGet32 (PcdFlashNvStorageFtwWorkingBase) > + ); > + *Length = (UINT64)PcdGet32 (PcdFlashNvStorageFtwWorkingSize); > + } > + > + return EFI_SUCCESS; > +} > diff --git a/MdeModulePkg/Include/Library/VariableFlashInfoLib.h b/MdeModulePkg/Include/Library/VariableFlashInfoLib.h > new file mode 100644 > index 000000000000..1367be9376ea > --- /dev/null > +++ b/MdeModulePkg/Include/Library/VariableFlashInfoLib.h > @@ -0,0 +1,68 @@ > +/** @file > + Variable Flash Information Library > + > +Copyright (c) Microsoft Corporation
> +SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef VARIABLE_FLASH_INFO_LIB_H_ > +#define VARIABLE_FLASH_INFO_LIB_H_ > + > +/** > + Get the base address and size for the NV storage area used for UEFI variable storage. > + > + @param[out] BaseAddress The NV storage base address. > + @param[out] Length The NV storage length in bytes. > + > + @retval EFI_SUCCESS NV storage information was found successfully. > + @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL. > + @retval EFI_NOT_FOUND NV storage information could not be found. > + > +**/ > +EFI_STATUS > +EFIAPI > +GetVariableFlashNvStorageInfo ( > + OUT EFI_PHYSICAL_ADDRESS *BaseAddress, > + OUT UINT64 *Length > + ); > + > +/** > + Get the base address and size for the fault tolerant write (FTW) spare > + area used for UEFI variable storage. > + > + @param[out] BaseAddress The FTW spare base address. > + @param[out] Length The FTW spare length in bytes. > + > + @retval EFI_SUCCESS FTW spare information was found successfully. > + @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL. > + @retval EFI_NOT_FOUND FTW spare information could not be found. > + > +**/ > +EFI_STATUS > +EFIAPI > +GetVariableFlashFtwSpareInfo ( > + OUT EFI_PHYSICAL_ADDRESS *BaseAddress, > + OUT UINT64 *Length > + ); > + > +/** > + Get the base address and size for the fault tolerant write (FTW) working > + area used for UEFI variable storage. > + > + @param[out] BaseAddress The FTW working area base address. > + @param[out] Length The FTW working area length in bytes. > + > + @retval EFI_SUCCESS FTW working information was found successfully. > + @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL. > + @retval EFI_NOT_FOUND FTW working information could not be found. > + > +**/ > +EFI_STATUS > +EFIAPI > +GetVariableFlashFtwWorkingInfo ( > + OUT EFI_PHYSICAL_ADDRESS *BaseAddress, > + OUT UINT64 *Length > + ); > + > +#endif > diff --git a/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf > new file mode 100644 > index 000000000000..70175e75f9b1 > --- /dev/null > +++ b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf > @@ -0,0 +1,48 @@ > +## @file > +# Variable Flash Information Library > +# > +# Provides services to access UEFI variable flash information. > +# > +# Copyright (c) Microsoft Corporation
> +# SPDX-License-Identifier: BSD-2-Clause-Patent > +## > + > +[Defines] > + INF_VERSION = 0x00010005 > + BASE_NAME = BaseVariableFlashInfoLib > + MODULE_UNI_FILE = BaseVariableFlashInfoLib.uni > + FILE_GUID = DEC426C9-C92E-4BAD-8E93-3F61C261118B > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = VariableFlashInfoLib > + > +# > +# The following information is for reference only and not required by the build tools. > +# > +# VALID_ARCHITECTURES = ANY > +# > + > +[Sources] > + BaseVariableFlashInfoLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + > +[LibraryClasses] > + DebugLib > + HobLib > + > +[Guids] > + gVariableFlashInfoHobGuid ## CONSUMES ## HOB > + > +[Pcd] > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## SOMETIMES_CONSUMES > diff --git a/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni > new file mode 100644 > index 000000000000..9a5348fa02a0 > --- /dev/null > +++ b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni > @@ -0,0 +1,12 @@ > +// /** @file > +// Variable Flash Information Library > +// > +// Copyright (c) Microsoft Corporation
> +// > +// SPDX-License-Identifier: BSD-2-Clause-Patent > +// > +// **/ > + > +#string STR_MODULE_ABSTRACT #language en-US "UEFI variable flash information library" > + > +#string STR_MODULE_DESCRIPTION #language en-US "Provides services to access UEFI variable flash information." > diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec > index 4e82f5836096..2bcb9f9453af 100644 > --- a/MdeModulePkg/MdeModulePkg.dec > +++ b/MdeModulePkg/MdeModulePkg.dec > @@ -154,6 +154,10 @@ [LibraryClasses] > # > VariablePolicyHelperLib|Include/Library/VariablePolicyHelperLib.h > > + ## @libraryclass Provides services to access UEFI variable flash information. > + # > + VariableFlashInfoLib|Include/Library/VariableFlashInfoLib.h > + > [Guids] > ## MdeModule package token space guid > # Include/Guid/MdeModulePkgTokenSpace.h > diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc > index b1d83461865e..90a0a7ec4a7c 100644 > --- a/MdeModulePkg/MdeModulePkg.dsc > +++ b/MdeModulePkg/MdeModulePkg.dsc > @@ -103,6 +103,7 @@ [LibraryClasses] > DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdateProgressLibGraphics.inf > VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf > MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf > + VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf > > [LibraryClasses.EBC.PEIM] > IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf > @@ -440,6 +441,7 @@ [Components] > MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.inf > MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf > MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf > + MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf > > [Components.IA32, Components.X64, Components.AARCH64] > MdeModulePkg/Universal/EbcDxe/EbcDxe.inf