From: "Yao, Jiewen" <jiewen.yao@intel.com>
To: "Mudusuru, Giri P" <giri.p.mudusuru@intel.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Zeng, Star" <star.zeng@intel.com>,
"Kinney, Michael D" <michael.d.kinney@intel.com>
Subject: Re: [PATCH] IntelSiliconPkg: Add DxeSmbiosDataHobLib
Date: Thu, 17 Nov 2016 08:46:40 +0000 [thread overview]
Message-ID: <74D8A39837DF1E4DA445A8C0B3885C50386D66CF@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <32baa8ac1e6c73081e0e66ae9aeaffca8e709873.1479108165.git.giri.p.mudusuru@intel.com>
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 <jiewen.yao@intel.com>; Zeng, Star <star.zeng@intel.com>;
> Kinney, Michael D <michael.d.kinney@intel.com>
> Subject: [edk2][PATCH] IntelSiliconPkg: Add DxeSmbiosDataHobLib
>
> Added NULL Library constructor DxeSmbiosDataHobLib which adds SMBIOS
> records from gIntelSmbiosDataHobGuid HOB to SMBIOS table using
> SMBIOS protocol.
>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Michael Kinney <michael.d.kinney@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Giri P Mudusuru <giri.p.mudusuru@intel.com>
> ---
> .../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
>
> 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.<BR>
> +
> + 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 <IndustryStandard/SmBios.h>
> +#include <Library/UefiLib.h>
> +#include <Library/BaseLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/HobLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +#include <Protocol/Smbios.h>
> +
> +/**
> +
> + 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 == NULL || NumberOfStrings == NULL) {
> + return EFI_INVALID_PARAMETER;
> + }
> +
> + FullSize = Head->Length;
> + CharInStr = (INT8*)Head + Head->Length;
> + *Size = FullSize;
> + *NumberOfStrings = 0;
> + StrLen = 0;
> +
> + //
> + // look for the two consecutive zeros, check the string limit by the way.
> + //
> + while (*CharInStr != 0 || *(CharInStr+1) != 0) {
> + if (*CharInStr == 0) {
> + *Size += 1;
> + CharInStr++;
> + }
> +
> + if (This->MajorVersion < 2 || (This->MajorVersion == 2 &&
> This->MinorVersion < 7)) {
> + MaxLen = SMBIOS_STRING_MAX_LENGTH;
> + } else if (This->MajorVersion < 3) {
> + //
> + // Reference SMBIOS 2.7, chapter 6.1.3, it will have no limit on the
> length of each individual text string.
> + // However, the length of the entire structure table (including all
> strings) must be reported
> + // in the Structure Table Length field of the SMBIOS Structure Table
> Entry Point,
> + // which is a WORD field limited to 65,535 bytes.
> + //
> + MaxLen = 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 = SMBIOS_3_0_TABLE_MAX_LENGTH;
> + }
> +
> + for (StrLen = 0 ; StrLen < MaxLen; StrLen++) {
> + if (*(CharInStr+StrLen) == 0) {
> + break;
> + }
> + }
> +
> + if (StrLen == MaxLen) {
> + return EFI_INVALID_PARAMETER;
> + }
> +
> + //
> + // forward the pointer
> + //
> + CharInStr += StrLen;
> + *Size += StrLen;
> + *NumberOfStrings += 1;
> + }
> +
> + //
> + // count ending two zeros.
> + //
> + *Size += 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 = 0;
> +
> + DEBUG ((DEBUG_INFO, "Adding SMBIOS records from HOB..\n"));
> +
> + Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID
> **)&Smbios);
> + if (Smbios == NULL) {
> + DEBUG ((DEBUG_WARN, " Can't locate SMBIOS protocol\n"));
> + return EFI_UNSUPPORTED;
> + }
> +
> + ///
> + /// Get SMBIOS HOB data
> + ///
> + for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST(Hob); Hob.Raw =
> GET_NEXT_HOB (Hob)) {
> + if ((GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_GUID_EXTENSION) &&
> (CompareGuid (&Hob.Guid->Name, &gIntelSmbiosDataHobGuid))) {
> + RecordPtr = (UINT8 *)Hob.Raw + sizeof (EFI_HOB_GUID_TYPE);
> + MaxPayloadSize = Hob.Guid->Header.HobLength - sizeof
> (EFI_HOB_GUID_TYPE);
> +
> + InstalledPayloadSize = 0;
> + do {
> + StructureSize = 0;
> + Status = GetSmbiosStructureSize (Smbios,
> (EFI_SMBIOS_TABLE_HEADER *)RecordPtr, &StructureSize,
> &NumberOfStrings);
> + if ((Status == EFI_SUCCESS) && (InstalledPayloadSize +
> StructureSize <= MaxPayloadSize)) {
> + InstalledPayloadSize += StructureSize;
> +
> + ///
> + /// Add generic SMBIOS HOB to SMBIOS table
> + ///
> + DEBUG ((DEBUG_VERBOSE, " Add SMBIOS record type: %x\n",
> ((EFI_SMBIOS_TABLE_HEADER *) RecordPtr)->Type));
> + SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
> + Status = Smbios->Add (Smbios, NULL, &SmbiosHandle,
> (EFI_SMBIOS_TABLE_HEADER *) RecordPtr);
> + if (!EFI_ERROR (Status)) {
> + RecordPtr += 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.<BR>
> +#
> +# 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 = 0x00010017
> +BASE_NAME = DxeSmbiosDataHobLib
> +FILE_GUID = AF55A9B6-2AE6-4B08-8CF7-750B7CBF49D7
> +MODULE_TYPE = DXE_DRIVER
> +LIBRARY_CLASS = NULL|DXE_DRIVER
> +CONSTRUCTOR = 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
prev parent reply other threads:[~2016-11-17 8:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-14 7:26 [PATCH] IntelSiliconPkg: Add DxeSmbiosDataHobLib Giri P Mudusuru
2016-11-17 8:46 ` Yao, Jiewen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=74D8A39837DF1E4DA445A8C0B3885C50386D66CF@shsmsx102.ccr.corp.intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox