From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web09.8603.1623129665595129973 for ; Mon, 07 Jun 2021 22:21:05 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=LLne1at1; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: hao.a.wu@intel.com) IronPort-SDR: JS3a2phO0cFqilOuMMHsHQBNsh1ZOcgSXogW+Rd/MDi/mKT/um+/Xvu8e+0xFAEoXCUBQ83zzC l8zGkL5s0WGw== X-IronPort-AV: E=McAfee;i="6200,9189,10008"; a="226115022" X-IronPort-AV: E=Sophos;i="5.83,256,1616482800"; d="scan'208";a="226115022" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jun 2021 22:21:04 -0700 IronPort-SDR: qgCscjzVL7WuTAdlMnoTVKmgw9ijjFrltgPfKz2e75wlXPKG6j57JQAKINhxZ0xhTgyF6RXpw/ EvaePxYcO0Tw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,256,1616482800"; d="scan'208";a="440331894" Received: from orsmsx605.amr.corp.intel.com ([10.22.229.18]) by orsmga007.jf.intel.com with ESMTP; 07 Jun 2021 22:21:03 -0700 Received: from orsmsx602.amr.corp.intel.com (10.22.229.15) by ORSMSX605.amr.corp.intel.com (10.22.229.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Mon, 7 Jun 2021 22:21:03 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4 via Frontend Transport; Mon, 7 Jun 2021 22:21:03 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.174) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.4; Mon, 7 Jun 2021 22:21:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XuPtuQT1aDaao/d7daFm0cbsuRKHcyH913xulIcIm33iOp2jK2cC52uqNYT4+Lzgz4oRU6iXE5S6quyVkIr3F7CCsS1r125GKPUCH+kSdo4FamgVSl65vmg8FSOzZ7ALLAnb8tHAHxLAI518kCCEYYW6lx2Xgx3rB8qDnaBlIgR1pkCMnUy+H4AQpiQ22QGjU3nLTFlwF0/Sklj8Rk2oMA0Vi0vHVF5731ORahcI0b5VtZPt+Od50DCQWWBSwGN7x7CkSHnLCXtWPwTjWjvnvZD9sPzIn4ZzUD5vUqdU9/+6nFzeXEdoHV/oSHZV5xpSXpn4nKo1JaNTA0eku6hQ6g== 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-SenderADCheck; bh=NbD4u4aF4yrfY4oLs//4W7SmETG/GcQsyIclThBME90=; b=EyR+2V8RgCocF2qJAqIO/aqU+HGLD1wJ1JFEFzpe0lc2EKgWDoYmfVxMcRSDclhnTMUrU3C1OzNMZQ5W9DnH5FTOajIxMHFW8Prip3upEMtdUQdcJDqoawCCDo+gxQI/IReXXyNJjhfefHe54B7kQFQigWM+wo0hn0bSNYv8aeUPUlXibiwBfBTTrcp73U8MnRIjHWnv1gsfrj+JzbppLtXbTTTSR3TDc/ri5IwRYvs06hVF909B1q9zILMmNxOny9oQkFi50+U2awYevqp6xdJOK6lB0SEJFpYUqnr6QtOjpLMj1UL7Zi+vAvhDWRkMoaBxk88q7IDfEcU5MhQ/nQ== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NbD4u4aF4yrfY4oLs//4W7SmETG/GcQsyIclThBME90=; b=LLne1at1kVNEpR7OTED1v1w3G1sbwXDy++g5/AdYmP8DcsdEVFetLITKAXHW2cD7rrFxvmnxUKfTcWXi16y8blt8u05Dlc1aJNfKbtO/3hJXUOyITYp2nCD3AMi6AvVP79EKHHQP0FtkoSbUozxOwOR79TqIG221tzpfXQnc1IQ= Received: from BN8PR11MB3666.namprd11.prod.outlook.com (2603:10b6:408:8c::19) by BN6PR1101MB2355.namprd11.prod.outlook.com (2603:10b6:404:94::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.22; Tue, 8 Jun 2021 05:21:01 +0000 Received: from BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::b9d0:5694:1b70:c031]) by BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::b9d0:5694:1b70:c031%4]) with mapi id 15.20.4195.030; Tue, 8 Jun 2021 05:21:01 +0000 From: "Wu, Hao A" To: "Liu, Zhiguang" , "devel@edk2.groups.io" CC: "Wang, Jian J" , "Bi, Dandan" , "Zeng, Star" , "Gao, Zhichao" , Patrick Rudolph Subject: Re: [Patch V3 5/9] MdeModulePkg/Universal/SmbiosDxe: Scan for existing tables Thread-Topic: [Patch V3 5/9] MdeModulePkg/Universal/SmbiosDxe: Scan for existing tables Thread-Index: AQHXWSX9DYwDDNr780SO2my0WPc6LKsJkjdw Date: Tue, 8 Jun 2021 05:21:01 +0000 Message-ID: References: <20210604094227.1890-1-zhiguang.liu@intel.com> <20210604094227.1890-6-zhiguang.liu@intel.com> In-Reply-To: <20210604094227.1890-6-zhiguang.liu@intel.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: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.143.16] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 71e60486-50b9-4a57-c200-08d92a3d34ec x-ms-traffictypediagnostic: BN6PR1101MB2355: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:513; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 55YWnPBomJssg+Ul6Vs4Yvi1mVj8OSxnBAF4ymUpiur9WghHprGwpl895QtYO0mXWK3z0zccmqWS/yqQpqdFdTu84LuSWRddOU/w9nPTYCCGUz4T9xrGHKXP1pLf0c3NcRu2Tslb4QQSJgAoScfxwGCDL49GSGZ06jpbq20+9jCAn+65jxZW68wheQ3/CUp+l49ZjuW+oZUB6Bq7/sbFQFnhipiY+W9ahlUDuW0D3rvFd+7rzFWryciPhWwbqcph57JrORWB+7bXQce6zAeG1aH0TE+AWsmyoEnaiKYoD4ncaNYvPBdxHsLAb14JSGam3m/ZQ18lRYfOyvetHSMnv/hJj/6AkdzJXyWRWcM7E1C2NqdtaEHdP05DOBlNw4xkUmJeMbhVoJsichTyJM0ONuEqU4CsaACqKb3MrqO1nr1MAVnhAJ2Bi1NP9T7hrKmn/f0mzk9Nq1NXlvSrvqT9d/KJJk03OioQgG4QqMdD91zJeN1BppRV5O8OwKlxSY1rK7Yq0DUIW1YQNbTsUnOv9LFkhXy5DIO5RrkFMnTCt4mBe2IxzsUsu6z1mNgrjvE8J8Pc7f3lYNBgIgAtGVXkk/zAkkN7NKFbT6K6fvclaFM= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR11MB3666.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(396003)(366004)(376002)(346002)(136003)(86362001)(110136005)(55016002)(316002)(54906003)(7696005)(30864003)(52536014)(33656002)(53546011)(6506007)(5660300002)(186003)(26005)(38100700002)(8676002)(2906002)(64756008)(66476007)(66446008)(66946007)(76116006)(9686003)(66556008)(83380400001)(8936002)(71200400001)(122000001)(478600001)(4326008)(19627235002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Zn+khIDBwhgznCBEQG9hkh1o8nK9ZDWmD/Fa1nFc6WiayYe7eO81buPChj4d?= =?us-ascii?Q?2Tt6Cr8Zwfm5LaVq/v3fdy7H/XyUM2MQADIJHXPNvdN4ZoBYpz/M5qMpnrio?= =?us-ascii?Q?uYShg89eyl4mjh3GSK8uGh3tDyzuCEdeuK/pECsi0TUBrRw1nzdJQug5+RbJ?= =?us-ascii?Q?MYxbuibbWZNlB7vwuQqP6wBXT6+R9GiKhNAMg8KF1JKu/iU/a4GcgavunTNx?= =?us-ascii?Q?ughBJbcWzmSMsJ9aTh8279JWVhNpESMX+h80taq9Ak3rIl+CYXccb48D2qyj?= =?us-ascii?Q?TalG3gruJoYjZFxRRfFr9JRfFp0UHqxvXs/uxQnAkR6bvZDEAcahIBsH4YcA?= =?us-ascii?Q?KqStTRiADBuZnM5bPyWe3CSFQpI7oWML1OjH5qVuMPBEWhuJKbgzu1X16DxH?= =?us-ascii?Q?dv6nY9i9HK9dis90rkyqyZvm+ZjxBWStkZhQjTGAHsMsCs+fwQ1X6p3V0q1F?= =?us-ascii?Q?DiCoISFu1r/2kZStkDiywq8MscY8vkxCJeVWslXa4DExDDlhfWLDvqWmjPUw?= =?us-ascii?Q?sX5OtJs7xLILS6UI2ueisEl8jflve57RCgLHbltVSMbhBsUtOkLJLaGOTkRe?= =?us-ascii?Q?6lQyT0BEN/VqdmBfHo+K0d9OL1eheZA2YHXlPp1qGPOmGF1nGRYWsYOy+9FT?= =?us-ascii?Q?nzFGyk/Zb6pACxklhQGPet1EUi8Z3nZyIVZ+XbcescZ45ptcYZJIBKWGZcc7?= =?us-ascii?Q?1XMYr1ZtCnl8lRn9x6pxwURoDOyTPUXs6jsRA3lM+dakHZVwHYAtVJWKxxI6?= =?us-ascii?Q?p8i8CEc6k1Ln/q/+M6e0lUOT4jPOz7FrvA35kXwkv2y79Mw9kOaSyAKjWeNI?= =?us-ascii?Q?gtsEhxyunHfsPv0BV/x2ZgJNJhcBo5q2y65zeoURNkJEKQ7GApxVxoxrYUjo?= =?us-ascii?Q?9RUE/C2jmheP8Hwi04vWVI0cIyYx6mXXzH4cy/H5jeG7o7SY9NwhGmqTt0i/?= =?us-ascii?Q?8ivmFHMmxi+KCggtFVrUr1IjPc5hssVNyO0qx8xLsc6TKMjZBlD+SNE3pT4l?= =?us-ascii?Q?OvKeBeuTHztNTdR5EfLVptR82BjsqPdXE63uB0Di/lbr6VdUpnuW1XvaL+iR?= =?us-ascii?Q?k4yJCcBtyWww+SV1N2lKl/ODImGDJmQXf0fvwseTXKOXAFtLOE046yMkWzwI?= =?us-ascii?Q?1PV3w63LxbbXecq/QkOfPvQqwOXNAniUG1w6d9gOZ4Vuw0lP/3yulNLBpTBR?= =?us-ascii?Q?BGoy0eVYreQQvSMzcLVi7oLaOyvvHDMHtEobNofh69dGmHfvwFEECxoqdeLA?= =?us-ascii?Q?0GKQT2jXE13hFMaSbROnIlT8wR/EOz2EO0H9HvoF72iyJ9jLjTe64vlUbDSF?= =?us-ascii?Q?tbGfLwPW30MwsQdflcnl9Om8?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN8PR11MB3666.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71e60486-50b9-4a57-c200-08d92a3d34ec X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Jun 2021 05:21:01.7619 (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: KoTmOB/ncO7EpVmz5/Mi9VJRQ2jS7k8TJF9KgSe+2B/PrAhCKdCRGVu18J75A04796y0x3mIhRQcxacKl9ezdQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1101MB2355 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 > -----Original Message----- > From: Liu, Zhiguang > Sent: Friday, June 4, 2021 5:42 PM > To: devel@edk2.groups.io > Cc: Wang, Jian J ; Wu, Hao A ; > Bi, Dandan ; Zeng, Star ; Gao, > Zhichao ; Patrick Rudolph > > Subject: [Patch V3 5/9] MdeModulePkg/Universal/SmbiosDxe: Scan for > existing tables >=20 > V1: > The default EfiSmbiosProtocol operates on an empty SMBIOS table. > The SMBIOS tables are provided by the bootloader on UefiPayloadPkg. > Scan for existing tables in SmbiosDxe and load them if they seem valid. >=20 > This fixes the settings menu not showing any hardware information, instea= d > only "0 MB RAM" was displayed. >=20 > Tests showed that the OS can still see the SMBIOS tables. >=20 > V2: > SmbiosDxe will get the SMBIOS from a guid Hob. > Aslo will keep the SmbiosHandle if it is available. Aslo -> Also >=20 > Cc: Jian J Wang > Cc: Hao A Wu > Cc: Dandan Bi > Cc: Star Zeng > Cc: Zhichao Gao > Signed-off-by: Patrick Rudolph > Signed-off-by: Zhiguang Liu > --- > MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c | 320 > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++-- > MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h | 4 +++- > MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf | 5 ++++- > 3 files changed, 325 insertions(+), 4 deletions(-) >=20 > diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c > b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c > index 3cdb0b1ed7..3579c4d890 100644 > --- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c > +++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c > @@ -2,7 +2,7 @@ > This code produces the Smbios protocol. It also responsible for constr= ucting >=20 > SMBIOS table into system table. >=20 >=20 >=20 > -Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
>=20 > +Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > **/ >=20 > @@ -148,6 +148,31 @@ SMBIOS_TABLE_3_0_ENTRY_POINT > Smbios30EntryPointStructureData =3D { > // >=20 > 0 >=20 > }; >=20 > + >=20 > +/** >=20 > + Validates a SMBIOS table entry point. >=20 > + >=20 > + @param TableEntry The SmBios table entry to validate. >=20 > + @param TableAddress On exit, point to the smbios table addres. >=20 > + @param TableMaximumSize On exit, point to the maximum size of the > table. >=20 > + >=20 > + @retval TRUE SMBIOS table entry point is valid. >=20 > + @retval FALSE SMBIOS table entry point is malformed. >=20 > + >=20 > +**/ >=20 > +typedef >=20 > +BOOLEAN >=20 > +(* IS_SMBIOS_TABLE_VALID) ( >=20 > + IN VOID *TableEntry, >=20 > + OUT VOID **TableAddress, >=20 > + OUT UINTN *TableMaximumSize >=20 > + ); >=20 > +typedef struct { >=20 > + EFI_GUID *Guid; >=20 > + IS_SMBIOS_TABLE_VALID IsValid; >=20 > +} IS_SMBIOS_TABLE_VALID_ENTRY; >=20 > + >=20 > + Could you help to put the above definitions into file "SmbiosDxe.h"? >=20 > /** >=20 >=20 >=20 > Get the full size of SMBIOS structure including optional strings that = follow > the formatted structure. >=20 > @@ -1408,6 +1433,296 @@ SmbiosTableConstruction ( > } >=20 > } >=20 >=20 >=20 > +/** >=20 > + Validates a SMBIOS 2.0 table entry point. >=20 > + >=20 > + @param TableEntry The SmBios table entry to validate. >=20 > + @param TableAddress On exit, point to the smbios table addres. >=20 > + @param TableMaximumSize On exit, point to the maximum size of the > table. >=20 > + >=20 > + @retval TRUE SMBIOS table entry point is valid. >=20 > + @retval FALSE SMBIOS table entry point is malformed. >=20 > + >=20 > +**/ >=20 > +STATIC >=20 > +BOOLEAN >=20 > +IsValidSmbios20Table ( >=20 > + IN VOID *TableEntry, >=20 > + OUT VOID **TableAddress, >=20 > + OUT UINTN *TableMaximumSize >=20 > + ) >=20 > +{ >=20 > + UINT8 Checksum; >=20 > + SMBIOS_TABLE_ENTRY_POINT *SmbiosTable; >=20 > + SmbiosTable =3D (SMBIOS_TABLE_ENTRY_POINT *) TableEntry; >=20 > + >=20 > + if (CompareMem (SmbiosTable->AnchorString, "_SM_", 4) !=3D 0) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + if (CompareMem (SmbiosTable->IntermediateAnchorString, "_DMI_", > 5) !=3D 0) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + // >=20 > + // The actual value of the EntryPointLength should be 1Fh. >=20 > + // However, it was incorrectly stated in version 2.1 of smbios specifi= cation. >=20 > + // Therefore, 0x1F and 0x1E are both accepted. >=20 > + // >=20 > + if (SmbiosTable->EntryPointLength !=3D 0x1E && SmbiosTable- > >EntryPointLength !=3D sizeof (SMBIOS_TABLE_ENTRY_POINT)) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + // >=20 > + // MajorVersion should not be less than 2. >=20 > + // >=20 > + if (SmbiosTable->MajorVersion < 2) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + // >=20 > + // The whole struct check sum should be zero >=20 > + // >=20 > + Checksum =3D CalculateSum8 ( >=20 > + (UINT8 *) SmbiosTable, >=20 > + SmbiosTable->EntryPointLength >=20 > + ); >=20 > + if (Checksum !=3D 0) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + // >=20 > + // The Intermediate Entry Point Structure check sum should be zero. >=20 > + // >=20 > + Checksum =3D CalculateSum8 ( >=20 > + (UINT8 *) SmbiosTable + OFFSET_OF > (SMBIOS_TABLE_ENTRY_POINT, IntermediateAnchorString), >=20 > + SmbiosTable->EntryPointLength - OFFSET_OF > (SMBIOS_TABLE_ENTRY_POINT, IntermediateAnchorString) >=20 > + ); >=20 > + if (Checksum !=3D 0) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + *TableAddress =3D (VOID *) (UINTN) SmbiosTable->TableAddress; >=20 > + *TableMaximumSize =3D SmbiosTable->TableLength; >=20 > + return TRUE; >=20 > +} >=20 > + >=20 > +/** >=20 > + Validates a SMBIOS 3.0 table entry point. >=20 > + >=20 > + @param TableEntry The SmBios table entry to validate. >=20 > + @param TableAddress On exit, point to the smbios table addres. >=20 > + @param TableMaximumSize On exit, point to the maximum size of the > table. >=20 > + >=20 > + @retval TRUE SMBIOS table entry point is valid. >=20 > + @retval FALSE SMBIOS table entry point is malformed. >=20 > + >=20 > +**/ >=20 > +STATIC >=20 > +BOOLEAN >=20 > +IsValidSmbios30Table ( >=20 > + IN VOID *TableEntry, >=20 > + OUT VOID **TableAddress, >=20 > + OUT UINTN *TableMaximumSize >=20 > + ) >=20 > +{ >=20 > + UINT8 Checksum; >=20 > + SMBIOS_TABLE_3_0_ENTRY_POINT *SmbiosTable; >=20 > + SmbiosTable =3D (SMBIOS_TABLE_3_0_ENTRY_POINT *) TableEntry; >=20 > + >=20 > + if (CompareMem (SmbiosTable->AnchorString, "_SM3_", 5) !=3D 0) { >=20 > + return FALSE; >=20 > + } >=20 > + if (SmbiosTable->EntryPointLength < sizeof > (SMBIOS_TABLE_3_0_ENTRY_POINT)) { >=20 > + return FALSE; >=20 > + } >=20 > + if (SmbiosTable->MajorVersion < 3) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + // >=20 > + // The whole struct check sum should be zero >=20 > + // >=20 > + Checksum =3D CalculateSum8 ( >=20 > + (UINT8 *) SmbiosTable, >=20 > + SmbiosTable->EntryPointLength >=20 > + ); >=20 > + if (Checksum !=3D 0) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + *TableAddress =3D (VOID *) (UINTN) SmbiosTable->TableAddress; >=20 > + *TableMaximumSize =3D SmbiosTable->TableMaximumSize; >=20 > + return TRUE; >=20 > +} >=20 > + >=20 > +/** >=20 > + Parse an existing SMBIOS table and insert it using SmbiosAdd. >=20 > + >=20 > + @param ImageHandle The EFI_HANDLE to this driver. >=20 > + @param Smbios The SMBIOS table to parse. >=20 > + @param Length The length of the SMBIOS table. >=20 > + >=20 > + @retval EFI_SUCCESS SMBIOS table was parsed and installed. >=20 > + @retval EFI_OUT_OF_RESOURCES Record was not added due to lack of > system resources. >=20 > + @retval EFI_INVALID_PARAMETER Smbios is not a correct smbios table >=20 > + >=20 > +**/ >=20 > +STATIC >=20 > +EFI_STATUS >=20 > +ParseAndAddExistingSmbiosTable ( >=20 > + IN EFI_HANDLE ImageHandle, >=20 > + IN SMBIOS_STRUCTURE_POINTER Smbios, >=20 > + IN UINTN Length >=20 > + ) >=20 > +{ >=20 > + EFI_STATUS Status; >=20 > + CHAR8 *String; >=20 > + EFI_SMBIOS_HANDLE SmbiosHandle; >=20 > + SMBIOS_STRUCTURE_POINTER SmbiosEnd; >=20 > + >=20 > + SmbiosEnd.Raw =3D Smbios.Raw + Length; >=20 > + >=20 > + if (Smbios.Raw >=3D SmbiosEnd.Raw || Smbios.Raw =3D=3D NULL) { >=20 > + return EFI_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + do { >=20 > + // >=20 > + // Make sure not to access memory beyond SmbiosEnd >=20 > + // >=20 > + if (Smbios.Raw + sizeof (SMBIOS_STRUCTURE) > SmbiosEnd.Raw || >=20 > + Smbios.Raw + sizeof (SMBIOS_STRUCTURE) < Smbios.Raw) { >=20 > + return EFI_INVALID_PARAMETER; >=20 > + } >=20 > + // >=20 > + // Check for end marker >=20 > + // >=20 > + if (Smbios.Hdr->Type =3D=3D SMBIOS_TYPE_END_OF_TABLE) { >=20 > + break; >=20 > + } >=20 > + // >=20 > + // Make sure not to access memory beyond SmbiosEnd >=20 > + // Each structure shall be terminated by a double-null (0000h). >=20 > + // >=20 > + if (Smbios.Raw + Smbios.Hdr->Length + 2 * sizeof (UINT8) > > SmbiosEnd.Raw || >=20 > + Smbios.Raw + Smbios.Hdr->Length + 2 * sizeof (UINT8) < Smbios.Raw)= { >=20 > + return EFI_INVALID_PARAMETER; >=20 > + } >=20 > + // >=20 > + // Install the table >=20 > + // >=20 > + SmbiosHandle =3D Smbios.Hdr->Handle; >=20 > + Status =3D SmbiosAdd ( >=20 > + &mPrivateData.Smbios, >=20 > + ImageHandle, >=20 > + &SmbiosHandle, >=20 > + Smbios.Hdr >=20 > + ); >=20 > + >=20 > + ASSERT_EFI_ERROR (Status); >=20 > + if (EFI_ERROR (Status)) { >=20 > + return Status; >=20 > + } >=20 > + // >=20 > + // Go to the next SMBIOS structure. Each SMBIOS structure may includ= e 2 > parts: >=20 > + // 1. Formatted section; 2. Unformatted string section. So, 2 steps = are > needed >=20 > + // to skip one SMBIOS structure. >=20 > + // >=20 > + >=20 > + // >=20 > + // Step 1: Skip over formatted section. >=20 > + // >=20 > + String =3D (CHAR8 *) (Smbios.Raw + Smbios.Hdr->Length); >=20 > + >=20 > + // >=20 > + // Step 2: Skip over unformatted string section. >=20 > + // >=20 > + do { >=20 > + // >=20 > + // Each string is terminated with a NULL(00h) BYTE and the sets of= strings >=20 > + // is terminated with an additional NULL(00h) BYTE. >=20 > + // >=20 > + for ( ; *String !=3D 0; String++) { >=20 > + if ((UINTN) String >=3D (UINTN) SmbiosEnd.Raw - sizeof (UINT8)) = { >=20 > + return EFI_INVALID_PARAMETER; >=20 > + } >=20 > + } >=20 > + >=20 > + if (*(UINT8 *) ++String =3D=3D 0) { >=20 > + // >=20 > + // Pointer to the next SMBIOS structure. >=20 > + // >=20 > + Smbios.Raw =3D (UINT8 *) ++String; >=20 > + break; >=20 > + } >=20 > + } while (TRUE); >=20 > + } while (Smbios.Raw < SmbiosEnd.Raw); >=20 > + >=20 > + return EFI_SUCCESS; >=20 > +} >=20 > + >=20 > + >=20 > +IS_SMBIOS_TABLE_VALID_ENTRY mIsSmbiosTableValid[] =3D { >=20 > + {&gPldSmbios3TableGuid, IsValidSmbios30Table }, >=20 > + {&gPldSmbiosTableGuid, IsValidSmbios20Table } >=20 > +}; Could you help to put this global variable to the beginning of this file? With the above 3 format comments handled: Reviewed-by: Hao A Wu Best Regards, Hao Wu >=20 > + >=20 > +/** >=20 > + Retrieve SMBIOS from Hob. >=20 > + @param ImageHandle Module's image handle >=20 > + >=20 > + @retval EFI_SUCCESS Smbios from Hob is installed. >=20 > + @return EFI_NOT_FOUND Not found Smbios from Hob. >=20 > + @retval Other No Smbios from Hob is installed. >=20 > + >=20 > +**/ >=20 > +EFI_STATUS >=20 > +RetrieveSmbiosFromHob ( >=20 > + IN EFI_HANDLE ImageHandle >=20 > + ) >=20 > +{ >=20 > + EFI_STATUS Status; >=20 > + UINTN Index; >=20 > + SMBIOS_STRUCTURE_POINTER Smbios; >=20 > + EFI_HOB_GUID_TYPE *GuidHob; >=20 > + PLD_SMBIOS_TABLE *SmBiosTableAdress; >=20 > + PLD_GENERIC_HEADER *GenericHeader; >=20 > + VOID *TableAddress; >=20 > + UINTN TableMaximumSize; >=20 > + >=20 > + Status =3D EFI_NOT_FOUND; >=20 > + >=20 > + for (Index =3D 0; Index < ARRAY_SIZE (mIsSmbiosTableValid); Index++) { >=20 > + GuidHob =3D GetFirstGuidHob (mIsSmbiosTableValid[Index].Guid); >=20 > + if (GuidHob =3D=3D NULL) { >=20 > + continue; >=20 > + } >=20 > + GenericHeader =3D (PLD_GENERIC_HEADER *) GET_GUID_HOB_DATA > (GuidHob); >=20 > + if ((sizeof (PLD_GENERIC_HEADER) <=3D GET_GUID_HOB_DATA_SIZE > (GuidHob)) && (GenericHeader->Length <=3D GET_GUID_HOB_DATA_SIZE > (GuidHob))) { >=20 > + if (GenericHeader->Revision =3D=3D PLD_SMBIOS_TABLE_REVISION) { >=20 > + // >=20 > + // PLD_SMBIOS_TABLE structure is used when Revision equals to > PLD_SMBIOS_TABLE_REVISION >=20 > + // >=20 > + SmBiosTableAdress =3D (PLD_SMBIOS_TABLE *) GET_GUID_HOB_DATA > (GuidHob); >=20 > + if (GenericHeader->Length >=3D PLD_SIZEOF_THROUGH_FIELD > (PLD_SMBIOS_TABLE, SmBiosEntryPoint)) { >=20 > + if (mIsSmbiosTableValid[Index].IsValid ((VOID *) > (UINTN )SmBiosTableAdress->SmBiosEntryPoint, &TableAddress, > &TableMaximumSize)) { >=20 > + Smbios.Raw =3D TableAddress; >=20 > + Status =3D ParseAndAddExistingSmbiosTable (ImageHandle, Smbi= os, > TableMaximumSize); >=20 > + if (EFI_ERROR (Status)) { >=20 > + DEBUG ((DEBUG_ERROR, "RetrieveSmbiosFromHob: Failed to par= se > preinstalled tables from gPldSmbios3TableGuid Guid Hob\n")); >=20 > + Status =3D EFI_UNSUPPORTED; >=20 > + } else { >=20 > + return EFI_SUCCESS; >=20 > + } >=20 > + } >=20 > + } >=20 > + } >=20 > + } >=20 > + } >=20 > + return Status; >=20 > +} >=20 > + >=20 > /** >=20 >=20 >=20 > Driver to produce Smbios protocol and pre-allocate 1 page for the fina= l > SMBIOS table. >=20 > @@ -1451,5 +1766,6 @@ SmbiosDriverEntryPoint ( > &mPrivateData.Smbios >=20 > ); >=20 >=20 >=20 > - return Status; >=20 > + RetrieveSmbiosFromHob (ImageHandle); >=20 > + return EFI_SUCCESS; >=20 > } >=20 > diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h > b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h > index f97c85ae40..a260cf695e 100644 > --- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h > +++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h > @@ -1,7 +1,7 @@ > /** @file >=20 > This code supports the implementation of the Smbios protocol >=20 >=20 >=20 > -Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
>=20 > +Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > **/ >=20 > @@ -24,6 +24,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #include >=20 > #include >=20 > #include >=20 > +#include >=20 > +#include >=20 >=20 >=20 > #define SMBIOS_INSTANCE_SIGNATURE SIGNATURE_32 ('S', 'B', 'i', 's') >=20 > typedef struct { >=20 > diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf > b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf > index f6c036e1dc..63f468936d 100644 > --- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf > +++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf > @@ -1,7 +1,7 @@ > ## @file >=20 > # This driver initializes and installs the SMBIOS protocol, constructs S= MBIOS > table into system configuration table. >=20 > # >=20 > -# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
>=20 > +# Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.
>=20 > # >=20 > # SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > # >=20 > @@ -41,6 +41,7 @@ > UefiDriverEntryPoint >=20 > DebugLib >=20 > PcdLib >=20 > + HobLib >=20 >=20 >=20 > [Protocols] >=20 > gEfiSmbiosProtocolGuid ## PRODUCES >=20 > @@ -48,6 +49,8 @@ > [Guids] >=20 > gEfiSmbiosTableGuid ## SOMETIMES_PRODUCE= S ## > SystemTable >=20 > gEfiSmbios3TableGuid ## SOMETIMES_PRODUCE= S ## > SystemTable >=20 > + gPldSmbios3TableGuid ## CONSUMES = ## HOB >=20 > + gPldSmbiosTableGuid ## SOMETIMES_CONSUME= S ## HOB >=20 >=20 >=20 > [Pcd] >=20 > gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion ## CONSUMES >=20 > -- > 2.30.0.windows.2