From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web09.2483.1649302314207276554 for ; Wed, 06 Apr 2022 20:31:54 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=dlz6vsn3; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: hao.a.wu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649302314; x=1680838314; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=WdaeRYlXhE71MKeqmGplzWbFFQajz0BmLl0j41vC1Rc=; b=dlz6vsn3tnLN22c54YTylu5/ZfkTd3RWNyeyXQd6ZxLAGNE3CtbmYldD MTVK6Bd+A7DOAPzBnf6keV12TERMus+YMgdbvLJhuv7qxS41hKyNUN56y yXMLflwoEu2qqWmkdp7QOSdUqQoy0jdiOos437wdubAnBCevWyi5/3E29 9h74gtmvDyd1++PIknQmub8aYWZuXoj9IhTOfArk/Wvt3jZsL+e3A7u+1 MCQDT1gtNzIQ4HcbDhIVx8ZMce8VH6OjolJgTUnICtYezhK7UX9yfTIn5 QnfJwURkJHgX/fb6RC83TL1diKwwGRdLaxBF4iapnQcLauho96SofAsjc w==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="260055538" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="260055538" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2022 20:31:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="570859571" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orsmga008.jf.intel.com with ESMTP; 06 Apr 2022 20:31:51 -0700 Received: from fmsmsx604.amr.corp.intel.com (10.18.126.84) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Wed, 6 Apr 2022 20:31:51 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Wed, 6 Apr 2022 20:31:51 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.175) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Wed, 6 Apr 2022 20:31:51 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ibsbJOKmRS0hJMjDxlpuF/Hzf7MEDWWzI+LXM7kKO2fqQr66S4/Wx27lCL1vYEKYAxyrd5yZM3uOF8L0bBX/KKERUajl+ykgWJSpEU5o6MVMjDS2uBXatWvJ2A7TyPsbJceZrf2Rvqv1KB9UCbYb/M1Nwws5x9OKDA0UNsKP72S2TAwBNJxddsE68vVapur5QYbjJWI26uVTHI7xMqHnhF5rWtKNMdc5dmA+9C41m71YDmsgu/j1RaNHfe4LQZ8HzcBIZv8oFn9uWHhfPUqgQbSoE3VE2HVPoykLKGEYYMr9a3+lpNEUZwSUjgvL6mkX1adbx9T78uT5XHDk+C/X9w== 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=y/VLZA4hbX6wvqcVhht4DHZt4pgLRC6tSauTCnnzMnk=; b=mphm5m08rIl8ucZW8XypUWT+F+q6Elv2gsxjgvjZxvN2RVq6LVK86CEXpfC8UCGSFkvte8v6SAPDW6gjokHePvy0DspyWvJWbPRhsD/dFk/C3qFXVINjRDmv21ePPsotdr2+vrWhZogM1sum84PeDIWKO+TOjgXiGBcm3CbnadE4HLGd+JkrsAJNnhMd+Lbi4H/+21NqvfHD1dLcAdk3MBQ3fcIQ7cqmeYf6YsjWgvhKptLIWnbcSsmdBEL6fPJ39bPa1EQXFl2xPD83HxbMUcRfFligsKcUn2djEG/rhPqg1obHDPe+JXThEF0vmzgu3yLMiWH7ru8qy4refkGVRA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from DM6PR11MB4025.namprd11.prod.outlook.com (2603:10b6:5:197::31) by SN6PR11MB3471.namprd11.prod.outlook.com (2603:10b6:805:c1::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.22; Thu, 7 Apr 2022 03:31:48 +0000 Received: from DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::7852:37e2:513c:470b]) by DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::7852:37e2:513c:470b%7]) with mapi id 15.20.5123.031; Thu, 7 Apr 2022 03:31:48 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "mikuback@linux.microsoft.com" CC: "Wang, Jian J" , "Gao, Liming" Subject: Re: [edk2-devel] [PATCH v1 2/3] MdeModulePkg/Variable: Consume Variable Info HOB Thread-Topic: [edk2-devel] [PATCH v1 2/3] MdeModulePkg/Variable: Consume Variable Info HOB Thread-Index: AQHYSdM5H6WlpyGgB0Sg6xLAxki9TKzjwJgg Date: Thu, 7 Apr 2022 03:31:48 +0000 Message-ID: References: <20220406162648.234-1-mikuback@linux.microsoft.com> <20220406162648.234-3-mikuback@linux.microsoft.com> In-Reply-To: <20220406162648.234-3-mikuback@linux.microsoft.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 479a5fe6-9a14-4c2b-ba50-08da18472618 x-ms-traffictypediagnostic: SN6PR11MB3471:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: +zVIfFiXBB0zOtLfnmKW58fUvZh91AGSR7RmVTN6E17A0Qea6FVahgP70V1BCqe/mAZpf1Yznw+t5sgLLGvYahNtcV7+ajjJS+u+7TGxtM4K7ZOdEsP0ZNYxrbpodKnx3mdXqmDpivty1Q5zXbaG0/CVw5x0upX45qig2hI51NHK24v//Xz8HhhEHJOC86K8TlTP4FOtIi1Xj5B0uf0SnAEve+uYwl1imk7PtYCRNLFomYkAbzGVYZFkWLne6dPwO7ZuNDLfUC81ecn9ZVeDTXIv+E0j+ZIPy2ZqqIDLMMbHkFmNm0PyeO7VSjfEJXFf3+Npcp3kETJB8bWjyRSI9LEwcBVun9BTbxWj83KtwtcG13JImUmT9d+bxA48CGUA7mZhaVTLWpL8yZkG5X4kUiy5rB5UEXvDj0Hq/w3UE44iAN43HjKqLHRX9I6QCqbhKBJ8wR8Zw9cXjZYTA+QAEYonD4XTHNZ01KUEJdq4vCpWMVF+Oqh3D27tENJmkXghQPb8ajAuKFXAO7UE/71pk1BPjQpeXo3UKWhiW74dVNAB+BHVSaJH6loT2AJD74nGf5Zj0QeBLUXyS+q8ljrkUQXerbajn8l39cJf/BfSsrROyB4R6ijSVGMNRJH0g0kOktQM3SRca5g9flovQ+Zi7caUQyByw6AstE0xvojHud2GY59X+kzIv9p20sBf9oMkaAPOUfwSMlkfB1bKdREitxrwsdFNtBr2PXUbwj93/ihiVOn2oWfeCXHVj2tchTILyFV+oMeU0rudPjTMI8uRY/h3bxwxXJCLVPO29HsfKIM3hRM2CiZkTbjyn2p3ggyQcczti5FmTFxVe1I0DfIj7A== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB4025.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(9686003)(7696005)(6506007)(26005)(19627235002)(54906003)(86362001)(316002)(5660300002)(186003)(2906002)(55016003)(53546011)(71200400001)(83380400001)(110136005)(508600001)(966005)(8936002)(30864003)(52536014)(33656002)(38100700002)(38070700005)(66556008)(4326008)(8676002)(66446008)(122000001)(64756008)(66476007)(66946007)(82960400001)(76116006)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?TSapqPnRNbsnzu+mTmgGzn4Jo2/yCu4dCG9aVgvO3lDToh7Ju4+iBmoIn198?= =?us-ascii?Q?iqTV9i61VhSG99CHU+NGB53v2naAUKn+SXrW1+BmGE+nbrbL6cHSTEU4D9mW?= =?us-ascii?Q?49mqdMCQneLVqKWiIu65LTBKtiSwJIVPEOsb8xvie4NzoYae2XZLXd+X9S7n?= =?us-ascii?Q?ftSyu+Leao53B6kj4xcyBeb4HXDGGIWbgw7l8YUwLHLR4CIrLx1dIXQUdcj8?= =?us-ascii?Q?phgDsWY0uT5Ho2YLOHAI/PxPPqOMQ6q0eb6A/K4+MKLDg6Lx68pNi9RgVnuY?= =?us-ascii?Q?539f09kzlnW8yAK6mSw7Qm7kioLYMGQoT1o5WYQxrwyFr3qlpR/JYiE6RcnH?= =?us-ascii?Q?VeXbUDXT4vsSRQ9ygD9XMXe1MABdIBsb+DsCvj6IxoICRJd1Uk3yJ20+EGPO?= =?us-ascii?Q?bcdWddW7ONhGbmo39Ac5X7FZj7REabAqhQSdNtPEVPcCcVjiCG5+/1t8ZZzJ?= =?us-ascii?Q?Miy8OUBEwUY4+ym9zaFZMy7ZiSCr65ANVLXfEqsbt17O9qHInziXN9J8qxlv?= =?us-ascii?Q?VPXo8tBEgce7+pngZ0qcx55hxw2Q8KAFEA+kNo5Nj97FEnh0Rk75ppB8FEkG?= =?us-ascii?Q?AcuQ0j0X1AlUItSJPs8SpMrCS2VUiEfFOtB0KAqApL+q6AE/fAevGCVAUOJ7?= =?us-ascii?Q?3VLed556P1X02zF1hvLRCXGYtey5HBX1E+BGgsKrApP7fHwHaRyObxWPU9Dh?= =?us-ascii?Q?9blk1yDILJX2rK5v3mHweRyVzw5Q7K8hsbuCblJBPVTrN43TMYRggH0rbKgU?= =?us-ascii?Q?gjrlLvGzdBHQ+XjQsTIkq2NJx0M3Vn4OfWaws1tQn+ka86RfXE1AHmVVdv/6?= =?us-ascii?Q?lKtr1c2cUa2nVK/qtldxbN4YBtHqjFjiVklhsT87tiqIOVEmuMQ9nzLy9T5N?= =?us-ascii?Q?qBAQ+F6FfhH+pg11tuhre7JHylk1aUd3xFcXBryGxqU018g7JsFarE/cYDVB?= =?us-ascii?Q?PC/8DSAZeGlPAfSghk4/PRHnETXJiNasA1cA84IHvIsw4wOfL7bI0A65NMTG?= =?us-ascii?Q?ZVB1AzQw0iF189yFfK0J0Popc0xhmA00hzQBQLhOe5vFXSGzgMeTNBxLUrqE?= =?us-ascii?Q?a4OKk/sVMy24hAxSvEbR7ljyIvTyIZWJ+NezUhCniKkmZwt2b5ndrm7Rridx?= =?us-ascii?Q?XbJtgJvxWjW0b/toLykgU6lPTwEiDA1qhgppfILdGlgxlWB4fZyOXcjA+8jk?= =?us-ascii?Q?7BWO/8q8WyetLQ5D9AryyARj8LgWkGD8X426IEi8IfDrR8IRGavFjy5Z9QJf?= =?us-ascii?Q?llpv9UJIoGzxidkXL5gDhn2B9QmKHgez6fUq42yDtBEeHALiu1uskA1qsqg4?= =?us-ascii?Q?JUHBxR5TmC+/udS6J4o9DFy+Q3zfvyE5eaY2wikeH60+f+UAsjems33nmRXp?= =?us-ascii?Q?EEsyWzZSNHa24X5sqx5Rwh7qdr1U3kXppQWp90cf2mQng7ZENL0xha5Jx0fI?= =?us-ascii?Q?JQE+te6YJJ+D2hg4OJnziqIaEDDm6VmzyjPxIpzcvavEUOJmNl3mnQsQeK8g?= =?us-ascii?Q?WKWI1PO0mGLNS8+b/kJ6oR/feLKyFzOlPfCq4SGrtojVr3t2HrSj+UP3TSBd?= =?us-ascii?Q?TQo0zaoky84Gwf/OCHChJeO/eqE1BQpVu/pbOz+23ugUQ6I3bgQc/3MTac3q?= =?us-ascii?Q?gmIPLXtSJxvrutV+qX4eOopj0BHR3oycvC2ugvP6Vd2lBo0PeGhYcLL9mLl2?= =?us-ascii?Q?Vki4iZ3tDwkBLlW3VoNfNF4pl0X8yADGHnOeYd8dXGQFWNDOQpKtGvewK1WC?= =?us-ascii?Q?2pbyY6DSBQ=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4025.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 479a5fe6-9a14-4c2b-ba50-08da18472618 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Apr 2022 03:31:48.6777 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: FSmYCjLl6PcSRLJyTVxh79gRqIjuh/hZ+duehzniKJupzJ58ILdZi4twZSpUvnDJmWg10KuzWw3a69Q2KqtwKw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3471 Return-Path: hao.a.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable One inline comment below: > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Michael > Kubacki > Sent: Thursday, April 7, 2022 12:27 AM > To: devel@edk2.groups.io > Cc: Wang, Jian J ; Wu, Hao A ; > Gao, Liming > Subject: [edk2-devel] [PATCH v1 2/3] MdeModulePkg/Variable: Consume > Variable Info HOB >=20 > From: Michael Kubacki >=20 > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479 >=20 > Updates VariableRuntimeDxe, VariableSmm, and VariableStandaloneMm > to acquire variable flash information from the Variable Flash > Information HOB. >=20 > If the HOB is not present, the drivers will continue to directly > read flash information from PCDs. >=20 > Cc: Jian J Wang > Cc: Hao A Wu > Cc: Liming Gao > Signed-off-by: Michael Kubacki > --- > MdeModulePkg/Universal/Variable/Pei/Variable.c | 66 > ++++++++++++++++++-- > MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 42 > +++++++++++++ > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c | 25 > ++++++-- > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c | 20 > ++++-- > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 20 > +++++- > MdeModulePkg/Universal/Variable/Pei/Variable.h | 2= + > MdeModulePkg/Universal/Variable/Pei/VariablePei.inf | 6= +- > MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h | 17= +++++ > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf | 6 > +- > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf | 6= +- > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 6 > +- > 11 files changed, 194 insertions(+), 22 deletions(-) >=20 > diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c > b/MdeModulePkg/Universal/Variable/Pei/Variable.c > index b36dd0de67b2..b19a26965ef2 100644 > --- a/MdeModulePkg/Universal/Variable/Pei/Variable.c > +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c > @@ -553,6 +553,48 @@ GetHobVariableStore ( > } > } >=20 > +/** > + Get the HOB that contains variable flash information. > + > + @param[out] VariableFlashInfo Pointer to a pointer to set to the var= iable > flash information structure. > + > + @retval EFI_SUCCESS Variable flash information was found s= uccessfully. > + @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is > NULL. > + @retval EFI_NOT_FOUND Variable flash information could not b= e found. > + > +**/ > +EFI_STATUS > +GetVariableFlashInfo ( > + OUT VARIABLE_FLASH_INFO **VariableFlashInfo > + ) > +{ > + EFI_HOB_GUID_TYPE *GuidHob; > + > + if (VariableFlashInfo =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + GuidHob =3D GetFirstGuidHob (&gVariableFlashInfoHobGuid); > + if (GuidHob =3D=3D NULL) { > + return EFI_NOT_FOUND; > + } > + > + *VariableFlashInfo =3D 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)) !=3D NULL)) { > + DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information > HOBs\n")); > + ASSERT (FALSE); > + } > + > + ); > + > + return EFI_SUCCESS; > +} > + > /** > Return the variable store header and the store info based on the Index= . >=20 > @@ -567,8 +609,10 @@ GetVariableStore ( > OUT VARIABLE_STORE_INFO *StoreInfo > ) > { > + EFI_STATUS Status; > EFI_HOB_GUID_TYPE *GuidHob; > EFI_FIRMWARE_VOLUME_HEADER *FvHeader; > + VARIABLE_FLASH_INFO *VariableFlashInfo; > VARIABLE_STORE_HEADER *VariableStoreHeader; > EFI_PHYSICAL_ADDRESS NvStorageBase; > UINT32 NvStorageSize; > @@ -591,11 +635,23 @@ GetVariableStore ( > // Emulated non-volatile variable mode is not enabled. > // >=20 > - NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize); > - NvStorageBase =3D (EFI_PHYSICAL_ADDRESS)(PcdGet64 > (PcdFlashNvStorageVariableBase64) !=3D 0 ? > - PcdGet64 (PcdFlashNvStora= geVariableBase64) : > - PcdGet32 (PcdFlashNvStora= geVariableBase) > - ); > + Status =3D GetVariableFlashInfo (&VariableFlashInfo); > + if (!EFI_ERROR (Status)) { > + NvStorageBase =3D VariableFlashInfo->NvStorageBaseAddress; > + Status =3D SafeUint64ToUint32 (VariableFlashInfo->NvSto= rageLength, > &NvStorageSize); > + // This driver currently assumes the size will be UINT32 so on= ly accept > + // that for now. > + ASSERT_EFI_ERROR (Status); > + } > + > + if (EFI_ERROR (Status)) { > + NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize); > + NvStorageBase =3D (EFI_PHYSICAL_ADDRESS)(PcdGet64 > (PcdFlashNvStorageVariableBase64) !=3D 0 ? > + PcdGet64 (PcdFlashNvSto= rageVariableBase64) : > + PcdGet32 (PcdFlashNvSto= rageVariableBase) > + ); > + } > + > ASSERT (NvStorageBase !=3D 0); >=20 > // > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c > b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c > index 6c1a3440ac8c..6ab4efd62a7e 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c > @@ -3701,6 +3701,48 @@ GetHobVariableStore ( > return EFI_SUCCESS; > } >=20 > +/** > + Get the HOB that contains variable flash information. > + > + @param[out] VariableFlashInfo Pointer to a pointer to set to the var= iable > flash information structure. > + > + @retval EFI_SUCCESS Variable flash information was found s= uccessfully. > + @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is > NULL. > + @retval EFI_NOT_FOUND Variable flash information could not b= e found. > + > +**/ > +EFI_STATUS > +GetVariableFlashInfo ( > + OUT VARIABLE_FLASH_INFO **VariableFlashInfo > + ) > +{ > + EFI_HOB_GUID_TYPE *GuidHob; > + > + if (VariableFlashInfo =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + GuidHob =3D GetFirstGuidHob (&gVariableFlashInfoHobGuid); > + if (GuidHob =3D=3D NULL) { > + return EFI_NOT_FOUND; > + } > + > + *VariableFlashInfo =3D 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)) !=3D NULL)) { > + DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information > HOBs\n")); > + ASSERT (FALSE); > + } > + > + ); > + > + return EFI_SUCCESS; > +} > + > /** > Initializes variable store area for non-volatile and volatile variable= . >=20 > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c > index 03fec3048dc4..1dc121d78e35 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c > @@ -416,6 +416,7 @@ FtwNotificationEvent ( > EFI_STATUS Status; > EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol; > EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol; > + VARIABLE_FLASH_INFO *VariableFlashInfo; > EFI_PHYSICAL_ADDRESS NvStorageVariableBase; > EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor; > EFI_PHYSICAL_ADDRESS BaseAddress; > @@ -423,6 +424,7 @@ FtwNotificationEvent ( > EFI_PHYSICAL_ADDRESS VariableStoreBase; > UINT64 VariableStoreLength; > UINTN FtwMaxBlockSize; > + UINT32 NvStorageVariableSize; >=20 > // > // Ensure FTW protocol is installed. > @@ -432,14 +434,29 @@ FtwNotificationEvent ( > return; > } >=20 > + Status =3D GetVariableFlashInfo (&VariableFlashInfo); > + if (!EFI_ERROR (Status)) { > + NvStorageVariableBase =3D VariableFlashInfo->NvStorageBaseAddress; > + Status =3D SafeUint64ToUint32 (VariableFlashInfo->NvS= torageLength, > &NvStorageVariableSize); > + // This driver currently assumes the size will be UINT32 so only acc= ept > + // that for now. > + ASSERT_EFI_ERROR (Status); > + } > + > + if (EFI_ERROR (Status)) { > + NvStorageVariableBase =3D NV_STORAGE_VARIABLE_BASE; > + NvStorageVariableSize =3D PcdGet32 (PcdFlashNvStorageVariableSize); > + } > + > + ASSERT (NvStorageVariableBase !=3D 0); > + > + VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache- > >HeaderLength; > + > Status =3D FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize= ); > if (!EFI_ERROR (Status)) { > - ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <=3D FtwMaxBlockSiz= e); > + ASSERT (NvStorageVariableSize <=3D FtwMaxBlockSize); > } >=20 > - NvStorageVariableBase =3D NV_STORAGE_VARIABLE_BASE; > - VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache- > >HeaderLength; > - > // > // Let NonVolatileVariableBase point to flash variable store base dire= ctly after > FTW ready. > // > diff --git > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c > index 5e9d40b67ac2..e424c210248a 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c > @@ -137,6 +137,7 @@ InitRealNonVolatileVariableStore ( > { > EFI_FIRMWARE_VOLUME_HEADER *FvHeader; > VARIABLE_STORE_HEADER *VariableStore; > + VARIABLE_FLASH_INFO *VariableFlashInfo; > UINT32 VariableStoreLength; > EFI_HOB_GUID_TYPE *GuidHob; > EFI_PHYSICAL_ADDRESS NvStorageBase; > @@ -153,19 +154,30 @@ InitRealNonVolatileVariableStore ( >=20 > mVariableModuleGlobal->FvbInstance =3D NULL; >=20 > + Status =3D GetVariableFlashInfo (&VariableFlashInfo); > + if (!EFI_ERROR (Status)) { > + NvStorageBase =3D VariableFlashInfo->NvStorageBaseAddress; > + Status =3D SafeUint64ToUint32 (VariableFlashInfo->NvStorageLe= ngth, > &NvStorageSize); > + // This driver currently assumes the size will be UINT32 so only acc= ept that > for now. > + ASSERT_EFI_ERROR (Status); > + } > + > + if (EFI_ERROR (Status)) { > + NvStorageBase =3D NV_STORAGE_VARIABLE_BASE; > + NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize); > + } > + > + ASSERT (NvStorageBase !=3D 0); > + > // > // Allocate runtime memory used for a memory copy of the FLASH region. > // Keep the memory and the FLASH in sync as updates occur. > // > - NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize); > NvStorageData =3D AllocateRuntimeZeroPool (NvStorageSize); > if (NvStorageData =3D=3D NULL) { > return EFI_OUT_OF_RESOURCES; > } >=20 > - NvStorageBase =3D NV_STORAGE_VARIABLE_BASE; > - ASSERT (NvStorageBase !=3D 0); > - > // > // Copy NV storage data to the memory buffer. > // > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > index 517cae7b00f8..c8667dd6ca34 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > @@ -1082,8 +1082,10 @@ SmmFtwNotificationEvent ( > EFI_PHYSICAL_ADDRESS VariableStoreBase; > EFI_SMM_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol; > EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol; > + VARIABLE_FLASH_INFO *VariableFlashInfo; > EFI_PHYSICAL_ADDRESS NvStorageVariableBase; > UINTN FtwMaxBlockSize; > + UINT32 NvStorageVariableSize; >=20 > if (mVariableModuleGlobal->FvbInstance !=3D NULL) { > return EFI_SUCCESS; > @@ -1097,9 +1099,25 @@ SmmFtwNotificationEvent ( > return Status; > } >=20 > + Status =3D GetVariableFlashInfo (&VariableFlashInfo); > + if (!EFI_ERROR (Status)) { > + NvStorageVariableBase =3D VariableFlashInfo->NvStorageBaseAddress; > + Status =3D SafeUint64ToUint32 (VariableFlashInfo->NvS= torageLength, > &NvStorageVariableSize); > + // This driver currently assumes the size will be UINT32 so only acc= ept that > for now. > + ASSERT_EFI_ERROR (Status); > + } > + > + if (EFI_ERROR (Status)) { > + NvStorageVariableBase =3D NV_STORAGE_VARIABLE_BASE; > + NvStorageVariableSize =3D PcdGet32 (PcdFlashNvStorageVariableSize); > + } > + > + ASSERT (NvStorageVariableBase !=3D 0); > + VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache- > >HeaderLength; It seems to me that the above line is not needed. Already done in existing = code several lines below. Best Regards, Hao Wu > + > Status =3D FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize= ); > if (!EFI_ERROR (Status)) { > - ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <=3D FtwMaxBlockSiz= e); > + ASSERT (NvStorageVariableSize <=3D FtwMaxBlockSize); > } >=20 > NvStorageVariableBase =3D NV_STORAGE_VARIABLE_BASE; > diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.h > b/MdeModulePkg/Universal/Variable/Pei/Variable.h > index 7f9ad5bfc357..b2ba30b841c1 100644 > --- a/MdeModulePkg/Universal/Variable/Pei/Variable.h > +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.h > @@ -20,7 +20,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #include > #include > #include > +#include >=20 > +#include > #include > #include > #include > diff --git a/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf > b/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf > index 7cbdd2385e8f..2557219f9b30 100644 > --- a/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf > +++ b/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf > @@ -39,6 +39,7 @@ [LibraryClasses] > DebugLib > PeiServicesTablePointerLib > PeiServicesLib > + SafeIntLib >=20 > [Guids] > ## CONSUMES ## GUID # Variable store header > @@ -54,14 +55,15 @@ [Guids] > ## SOMETIMES_CONSUMES ## HOB > ## CONSUMES ## GUID # Dependence > gEdkiiFaultTolerantWriteGuid > + gVariableFlashInfoHobGuid ## CONSUMES ## HOB >=20 > [Ppis] > gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES >=20 > [Pcd] > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## > SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## > CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## > SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## > SOMETIMES_CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable ## > SOMETIMES_CONSUMES >=20 > [Depex] > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h > b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h > index 31e408976a35..c9bbd1568567 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h > @@ -31,12 +31,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #include > #include > #include > +#include > #include > #include > #include > #include > #include > #include > +#include >=20 > #include "PrivilegePolymorphic.h" >=20 > @@ -126,6 +128,21 @@ typedef struct { > EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance; > } VARIABLE_MODULE_GLOBAL; >=20 > +/** > + Get the HOB that contains variable flash information. > + > + @param[out] VariableFlashInfo Pointer to a pointer to set to the var= iable > flash information structure. > + > + @retval EFI_SUCCESS Variable flash information was found s= uccessfully. > + @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is > NULL. > + @retval EFI_NOT_FOUND Variable flash information could not b= e found. > + > +**/ > +EFI_STATUS > +GetVariableFlashInfo ( > + OUT VARIABLE_FLASH_INFO **VariableFlashInfo > + ); > + > /** > Flush the HOB variable to flash. >=20 > diff --git > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf > index c9434df631ee..6df350afa260 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf > @@ -73,6 +73,7 @@ [LibraryClasses] > VarCheckLib > VariablePolicyLib > VariablePolicyHelperLib > + SafeIntLib >=20 > [Protocols] > gEfiFirmwareVolumeBlockProtocolGuid ## CONSUMES > @@ -114,6 +115,7 @@ [Guids] > gEfiSystemNvDataFvGuid ## CONSUMES = ## GUID > gEfiEndOfDxeEventGroupGuid ## CONSUMES = ## Event > gEdkiiFaultTolerantWriteGuid ## SOMETIMES_CONSUMES = ## HOB > + gVariableFlashInfoHobGuid ## CONSUMES = ## HOB >=20 > ## SOMETIMES_CONSUMES ## Variable:L"VarErrorFlag" > ## SOMETIMES_PRODUCES ## Variable:L"VarErrorFlag" > @@ -125,9 +127,9 @@ [Guids] > gEfiImageSecurityDatabaseGuid >=20 > [Pcd] > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## > SOMETIMES_CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## > SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## > SOMETIMES_CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## > CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## > CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## > CONSUMES > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf > index eaa97a01c6e5..398e7d9060ab 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf > @@ -82,6 +82,7 @@ [LibraryClasses] > UefiBootServicesTableLib > VariablePolicyLib > VariablePolicyHelperLib > + SafeIntLib >=20 > [Protocols] > gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES > @@ -121,15 +122,16 @@ [Guids] > gSmmVariableWriteGuid ## PRODUCES = ## GUID # Install > protocol > gEfiSystemNvDataFvGuid ## CONSUMES = ## GUID > gEdkiiFaultTolerantWriteGuid ## SOMETIMES_CONSUMES = ## HOB > + gVariableFlashInfoHobGuid ## CONSUMES = ## HOB >=20 > ## SOMETIMES_CONSUMES ## Variable:L"VarErrorFlag" > ## SOMETIMES_PRODUCES ## Variable:L"VarErrorFlag" > gEdkiiVarErrorFlagGuid >=20 > [Pcd] > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## > SOMETIMES_CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## > SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## > SOMETIMES_CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## > CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## > CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## > CONSUMES > diff --git > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf > index d8c4f77e7f1f..efc9290ae759 100644 > --- > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf > +++ > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf > @@ -73,6 +73,7 @@ [LibraryClasses] > HobLib > MemoryAllocationLib > MmServicesTableLib > + SafeIntLib > StandaloneMmDriverEntryPoint > SynchronizationLib > VarCheckLib > @@ -114,6 +115,7 @@ [Guids] >=20 > gEfiSystemNvDataFvGuid ## CONSUMES = ## GUID > gEdkiiFaultTolerantWriteGuid ## SOMETIMES_CONSUMES = ## HOB > + gVariableFlashInfoHobGuid ## CONSUMES = ## HOB >=20 > ## SOMETIMES_CONSUMES ## Variable:L"VarErrorFlag" > ## SOMETIMES_PRODUCES ## Variable:L"VarErrorFlag" > @@ -121,8 +123,8 @@ [Guids] >=20 > [Pcd] > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## > SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## > CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## > SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## > SOMETIMES_CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## > CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## > CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## > CONSUMES > -- > 2.28.0.windows.1 >=20 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#88463): https://edk2.groups.io/g/devel/message/88463 > Mute This Topic: https://groups.io/mt/90293666/1768737 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub [hao.a.wu@intel.com] > -=3D-=3D-=3D-=3D-=3D-=3D >=20