From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 00BE881F1B for ; Thu, 17 Nov 2016 00:46:38 -0800 (PST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP; 17 Nov 2016 00:46:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,504,1473145200"; d="scan'208";a="32302163" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga005.jf.intel.com with ESMTP; 17 Nov 2016 00:46:43 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 17 Nov 2016 00:46:43 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.239]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.142]) with mapi id 14.03.0248.002; Thu, 17 Nov 2016 16:46:41 +0800 From: "Yao, Jiewen" To: "Mudusuru, Giri P" , "edk2-devel@lists.01.org" CC: "Zeng, Star" , "Kinney, Michael D" Thread-Topic: [edk2][PATCH] IntelSiliconPkg: Add DxeSmbiosDataHobLib Thread-Index: AQHSPkiKxtRmh3XWNkmZ04n6uVC+36Dc4Z0g Date: Thu, 17 Nov 2016 08:46:40 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C50386D66CF@shsmsx102.ccr.corp.intel.com> References: <32baa8ac1e6c73081e0e66ae9aeaffca8e709873.1479108165.git.giri.p.mudusuru@intel.com> In-Reply-To: <32baa8ac1e6c73081e0e66ae9aeaffca8e709873.1479108165.git.giri.p.mudusuru@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] IntelSiliconPkg: Add DxeSmbiosDataHobLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Nov 2016 08:46:39 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: jiewen.yao@intel.com > -----Original Message----- > From: Mudusuru, Giri P > Sent: Monday, November 14, 2016 3:27 PM > To: edk2-devel@lists.01.org > Cc: Yao, Jiewen ; Zeng, Star ; > Kinney, Michael D > Subject: [edk2][PATCH] IntelSiliconPkg: Add DxeSmbiosDataHobLib >=20 > Added NULL Library constructor DxeSmbiosDataHobLib which adds SMBIOS > records from gIntelSmbiosDataHobGuid HOB to SMBIOS table using > SMBIOS protocol. >=20 > Cc: Jiewen Yao > Cc: Star Zeng > Cc: Michael Kinney > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Giri P Mudusuru > --- > .../DxeSmbiosDataHobLib/DxeSmbiosDataHobLib.c | 193 > +++++++++++++++++++++ > .../DxeSmbiosDataHobLib/DxeSmbiosDataHobLib.inf | 44 +++++ > 2 files changed, 237 insertions(+) > create mode 100644 > IntelSiliconPkg/Library/DxeSmbiosDataHobLib/DxeSmbiosDataHobLib.c > create mode 100644 > IntelSiliconPkg/Library/DxeSmbiosDataHobLib/DxeSmbiosDataHobLib.inf >=20 > diff --git > a/IntelSiliconPkg/Library/DxeSmbiosDataHobLib/DxeSmbiosDataHobLib.c > b/IntelSiliconPkg/Library/DxeSmbiosDataHobLib/DxeSmbiosDataHobLib.c > new file mode 100644 > index 0000000..8d513e0 > --- /dev/null > +++ > b/IntelSiliconPkg/Library/DxeSmbiosDataHobLib/DxeSmbiosDataHobLib.c > @@ -0,0 +1,193 @@ > +/** @file > + Library to add SMBIOS data records from HOB to SMBIOS table. > + > + Copyright (c) 2016, Intel Corporation. All rights reserved.
> + > + This program and the accompanying materials are licensed and made > available under > + the terms and conditions of the BSD License which accompanies this > distribution. > + The full text of the license may be found at > + http://opensource.org/licenses/bsd-license.php > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > + > + @par Specification Reference: > + System Management BIOS (SMBIOS) Reference Specification v3.0.0 > + dated 2015-Feb-12 (DSP0134) > + > http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3. > 0.0.pdf > + > +**/ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/** > + > + Get the full size of SMBIOS structure including optional strings that > follow the formatted structure. > + @note: This function is copy from SmbiosDxe in MdeModulePkg. > + > + @param[in] This The EFI_SMBIOS_PROTOCOL > instance. > + @param[in] Head Pointer to the beginning of > SMBIOS structure. > + @param[out] Size The returned size. > + @param[out] NumberOfStrings The returned number of optional > strings that follow the formatted structure. > + > + @retval EFI_SUCCESS Size returned in Size. > + @retval EFI_INVALID_PARAMETER Input SMBIOS structure mal-formed > or Size is NULL. > + > +**/ > +EFI_STATUS > +EFIAPI > +GetSmbiosStructureSize ( > + IN CONST EFI_SMBIOS_PROTOCOL *This, > + IN EFI_SMBIOS_TABLE_HEADER *Head, > + OUT UINTN *Size, > + OUT UINTN *NumberOfStrings > + ) > +{ > + UINTN FullSize; > + UINTN StrLen; > + UINTN MaxLen; > + INT8* CharInStr; > + > + if (Size =3D=3D NULL || NumberOfStrings =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + FullSize =3D Head->Length; > + CharInStr =3D (INT8*)Head + Head->Length; > + *Size =3D FullSize; > + *NumberOfStrings =3D 0; > + StrLen =3D 0; > + > + // > + // look for the two consecutive zeros, check the string limit by the w= ay. > + // > + while (*CharInStr !=3D 0 || *(CharInStr+1) !=3D 0) { > + if (*CharInStr =3D=3D 0) { > + *Size +=3D 1; > + CharInStr++; > + } > + > + if (This->MajorVersion < 2 || (This->MajorVersion =3D=3D 2 && > This->MinorVersion < 7)) { > + MaxLen =3D SMBIOS_STRING_MAX_LENGTH; > + } else if (This->MajorVersion < 3) { > + // > + // Reference SMBIOS 2.7, chapter 6.1.3, it will have no limit on t= he > length of each individual text string. > + // However, the length of the entire structure table (including al= l > strings) must be reported > + // in the Structure Table Length field of the SMBIOS Structure Tab= le > Entry Point, > + // which is a WORD field limited to 65,535 bytes. > + // > + MaxLen =3D SMBIOS_TABLE_MAX_LENGTH; > + } else { > + // > + // SMBIOS 3.0 defines the Structure table maximum size as DWORD > field limited to 0xFFFFFFFF bytes. > + // Locate the end of string as long as possible. > + // > + MaxLen =3D SMBIOS_3_0_TABLE_MAX_LENGTH; > + } > + > + for (StrLen =3D 0 ; StrLen < MaxLen; StrLen++) { > + if (*(CharInStr+StrLen) =3D=3D 0) { > + break; > + } > + } > + > + if (StrLen =3D=3D MaxLen) { > + return EFI_INVALID_PARAMETER; > + } > + > + // > + // forward the pointer > + // > + CharInStr +=3D StrLen; > + *Size +=3D StrLen; > + *NumberOfStrings +=3D 1; > + } > + > + // > + // count ending two zeros. > + // > + *Size +=3D 2; > + return EFI_SUCCESS; > +} > + > +/** > + Adds SMBIOS records to tables > + > + @param[in] ImageHandle Image handle of this driver. > + @param[in] SystemTable Global system service table. > + > + @retval EFI_UNSUPPORTED - Could not locate SMBIOS protocol > + @retval EFI_OUT_OF_RESOURCES - Failed to allocate memory for > SMBIOS HOB type. > + @retval EFI_SUCCESS - Successfully added SMBIOS records > based on HOB. > +**/ > +EFI_STATUS > +EFIAPI > +DxeSmbiosDataHobLibConstructor ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + EFI_PEI_HOB_POINTERS Hob; > + EFI_SMBIOS_HANDLE SmbiosHandle; > + EFI_SMBIOS_PROTOCOL *Smbios; > + EFI_STATUS Status; > + UINTN InstalledPayloadSize; > + UINTN MaxPayloadSize; > + UINT8 *RecordPtr; > + UINT16 RecordCount; > + UINTN StructureSize; > + UINTN NumberOfStrings; > + > + RecordCount =3D 0; > + > + DEBUG ((DEBUG_INFO, "Adding SMBIOS records from HOB..\n")); > + > + Status =3D gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID > **)&Smbios); > + if (Smbios =3D=3D NULL) { > + DEBUG ((DEBUG_WARN, " Can't locate SMBIOS protocol\n")); > + return EFI_UNSUPPORTED; > + } > + > + /// > + /// Get SMBIOS HOB data > + /// > + for (Hob.Raw =3D GetHobList (); !END_OF_HOB_LIST(Hob); Hob.Raw =3D > GET_NEXT_HOB (Hob)) { > + if ((GET_HOB_TYPE (Hob) =3D=3D EFI_HOB_TYPE_GUID_EXTENSION) && > (CompareGuid (&Hob.Guid->Name, &gIntelSmbiosDataHobGuid))) { > + RecordPtr =3D (UINT8 *)Hob.Raw + sizeof (EFI_HOB_GUID_TYPE); > + MaxPayloadSize =3D Hob.Guid->Header.HobLength - sizeof > (EFI_HOB_GUID_TYPE); > + > + InstalledPayloadSize =3D 0; > + do { > + StructureSize =3D 0; > + Status =3D GetSmbiosStructureSize (Smbios, > (EFI_SMBIOS_TABLE_HEADER *)RecordPtr, &StructureSize, > &NumberOfStrings); > + if ((Status =3D=3D EFI_SUCCESS) && (InstalledPayloadSize + > StructureSize <=3D MaxPayloadSize)) { > + InstalledPayloadSize +=3D StructureSize; > + > + /// > + /// Add generic SMBIOS HOB to SMBIOS table > + /// > + DEBUG ((DEBUG_VERBOSE, " Add SMBIOS record type: %x\n", > ((EFI_SMBIOS_TABLE_HEADER *) RecordPtr)->Type)); > + SmbiosHandle =3D SMBIOS_HANDLE_PI_RESERVED; > + Status =3D Smbios->Add (Smbios, NULL, &SmbiosHandle, > (EFI_SMBIOS_TABLE_HEADER *) RecordPtr); > + if (!EFI_ERROR (Status)) { > + RecordPtr +=3D StructureSize; > + RecordCount++; > + } > + } else { > + break; > + } > + } while (TRUE); > + } > + } > + DEBUG ((DEBUG_INFO, " Found %d Records and added to SMBIOS > table.\n", RecordCount)); > + > + return EFI_SUCCESS; > +} > + > diff --git > a/IntelSiliconPkg/Library/DxeSmbiosDataHobLib/DxeSmbiosDataHobLib.inf > b/IntelSiliconPkg/Library/DxeSmbiosDataHobLib/DxeSmbiosDataHobLib.inf > new file mode 100644 > index 0000000..afac26f > --- /dev/null > +++ > b/IntelSiliconPkg/Library/DxeSmbiosDataHobLib/DxeSmbiosDataHobLib.inf > @@ -0,0 +1,44 @@ > +## @file > +# Component INF file for the DxeSmbiosDataHob library. > +# > +# Copyright (c) 2016, Intel Corporation. All rights reserved.
> +# > +# This program and the accompanying materials are licensed and made > available under > +# the terms and conditions of the BSD License which accompanies this > distribution. > +# The full text of the license may be found at > +# http://opensource.org/licenses/bsd-license.php > +# > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > +# > +## > + > +[Defines] > +INF_VERSION =3D 0x00010017 > +BASE_NAME =3D DxeSmbiosDataHobLib > +FILE_GUID =3D AF55A9B6-2AE6-4B08-8CF7-750B7CBF49D7 > +MODULE_TYPE =3D DXE_DRIVER > +LIBRARY_CLASS =3D NULL|DXE_DRIVER > +CONSTRUCTOR =3D DxeSmbiosDataHobLibConstructor > + > +[Packages] > +MdePkg/MdePkg.dec > +IntelSiliconPkg/IntelSiliconPkg.dec > + > +[Sources] > +DxeSmbiosDataHobLib.c > + > +[LibraryClasses] > +DebugLib > +BaseMemoryLib > +MemoryAllocationLib > +BaseLib > +HobLib > +UefiLib > + > +[Guids] > +gIntelSmbiosDataHobGuid ## CONSUMES > + > +[Depex] > +gEfiSmbiosProtocolGuid > + > -- > 2.9.0.windows.1