From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 174B39414A4 for ; Fri, 26 Jan 2024 13:12:33 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=mOiAZfbNQ9tWloKmctfFegIpQ/oqQtTQoo2M6RvC8CQ=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1706274752; v=1; b=IN04LeONIlKLO2V1rsguB+6RKT4YE1k7ThhwsWwIywGxD8R1mzuUG9y8XlCvhCHDMWSn9uz5 MJQ/7ny1WCuA0TMrPRyeSuySitMdN6tVgfJAGXzlFKB4kitzGCEgysrvWUWbV13cT7r2oNtFH9m 7lBrURlt8PBfSGLXXAKajLe0= X-Received: by 127.0.0.2 with SMTP id WR3dYY7687511x1LpXmNrfZf; Fri, 26 Jan 2024 05:12:32 -0800 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.76]) by mx.groups.io with SMTP id smtpd.web11.15445.1706274746982383655 for ; Fri, 26 Jan 2024 05:12:27 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KlVwbJNJHr+QT35VH5JIagk3hzEB7jCxoIoHA2xfCRlOsX8XK30cb9k4LqdLZi/mOVl193WxehaTeF3H19xmscMqacTj1BDs2ebJ4RR0YUjo5IIiRxede0ZhDbk1C7bBk69YB6x0MGRQ8XeKM/aQhvcEJ2rJbcTIRBk6fyA3/g614N0lXTludPXvnY6uZlZC7CGHjhUHx5MA31VpsaHYaVsDdJTsamhBvMXekcjoT5Lzpi9pF0PmfOIscu/9MaBLka5R/UdgOsknShsEJKSmclKRo1qhItI568KkguNHj1Rssga/+spQvbVse6qyu+MtNfD5HEz+CO85ZG2zymLNzA== 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=qmBmjWWRdBhD3S2stGOFBt4Nds0ycMA3E84eLFPpE+4=; b=G/mKanZhCRMSA93ptTaIgUFUH90dytNiJDpq/CMe4ulRKmlUB1O8z4HAxuzcscAi+rS3R/4BHHpVHzP7cx8eZjEY1Jvk4cI9PO6gh564pG3IWGqVbHPbHRaB52athyHSgO1t+Imx2dQvM+YrNSaALQPQcKzcspoxGxInlH85r74WQ6CYzovAjMNgLTC88h2AcgKArH7wYzMyF7JiYeFHlG+r0JJykQx2B3CiuTY/ICVLMPJAJB6TU/FHdsnt/vAb6/3QyGB7oGFCBgXJ7Qzpabs0gdNc3lwZvaCC5ISzY9dubEFLeLxrVGlquTEsoeKc0VxzAj9VrDKWYS2Jfgb5Hg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) X-Received: from CY5PR14CA0012.namprd14.prod.outlook.com (2603:10b6:930:2::11) by CY8PR12MB8412.namprd12.prod.outlook.com (2603:10b6:930:6f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27; Fri, 26 Jan 2024 13:12:23 +0000 X-Received: from CY4PEPF0000E9CF.namprd03.prod.outlook.com (2603:10b6:930:2:cafe::ca) by CY5PR14CA0012.outlook.office365.com (2603:10b6:930:2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22 via Frontend Transport; Fri, 26 Jan 2024 13:12:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9CF.mail.protection.outlook.com (10.167.241.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7228.16 via Frontend Transport; Fri, 26 Jan 2024 13:12:23 +0000 X-Received: from SHA-LX-MINGXZHA.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 26 Jan 2024 07:12:21 -0600 From: "Zhai, MingXin (Duke) via groups.io" To: CC: Eric Xing , Ken Yao , Igniculus Fu , Abner Chang Subject: [edk2-devel] [PATCH V3 14/32] AMD/VanGoghBoard: Check in SmbiosLib Date: Fri, 26 Jan 2024 21:11:07 +0800 Message-ID: <20240126131125.1881-15-duke.zhai@amd.com> In-Reply-To: <20240126131125.1881-1-duke.zhai@amd.com> References: <20240126131125.1881-1-duke.zhai@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9CF:EE_|CY8PR12MB8412:EE_ X-MS-Office365-Filtering-Correlation-Id: 5b0e567c-0e8f-4d18-cde6-08dc1e706fa7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 1l4b2bTminiGnTpABZbv1+L8jcwdiEEuc74LbOX17POe2jBWZpSVJeRODsV8MNrLZopOyFv0u2rp4q0ozO4yGd521fj/V8HpyMDbeJ4+X/JdYcj/dRvJWdaU/QX4Cqu9oVwvkF4rlaRyXQuxMzD7xAfdsRuJlHmk1+vcf0ltdIj1j6lJJckzeq0h7/j/cSqXfeOF7Dt6AeX//t11b1VFKMAkCiPHpG2jbSSvzrx11UmxvxlCIohjgxALdSSIF9PpMH2hiPic4u4oZEUJMRGVKfZ0/hpEh1bhtK2cMjor1QhiL3Ob2pmU0sxY/cZqQxLEDaOJWjxBeH3p5HNRpwcx5xlMIZCc9rsMXLWOtHyR5/wz0EYOz1DQ8eZ+n077DkBmLUJpzdECEcmDLVwNTx7wmbhf3+kh5h5Q1ORP1K5Qg4c0xDF1Z8hkP+b9Y3jepe7Q69IIEgPvR3JPdRdqcIhw5JovNntmzDqcTIVH6Vo8rPhxBTZxZS7aCkoQzitn4s0yWYfAZKNopVh4yX3AxPkUT7AtUnS998DTFKcnjdeRzCeA2GD8izw56np/g5DG7Kc/hTaFusggCdpNvJMEBMR/+0QHJufmAn38i6e4QDkIBm8G6ZwPXoKEIHLS8yjLrEUuvCyMoXNN+uQdcrMqe/imM+O7xhU1gKbYZjiDyZtnUo1gXfTehcvN1m4SBLZrMXmr0kc+g8RqcD69EtxsbDjQUyLDO1S13t+V22pxDbyufYtb3pWbgcUlgfC+OUPrcu5hAEEP7hub7MmV7AFCKydnkQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 13:12:23.7112 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5b0e567c-0e8f-4d18-cde6-08dc1e706fa7 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9CF.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8412 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,duke.zhai@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: ppMGaMi5dAkn1j0ehm4u20Rmx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=IN04LeON; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: Duke Zhai BZ #:4640 In V3: Improve coding style follow edk2 C coding standard. 1.Remove macro definition extra underscores. 2.Putting some AMD copyright in the right place. In V2: Improve coding style. 1.Remove the leading underscore and use double underscore at trailing in = C header files. 2.Remove old tianocore licenses and redundant license description. 3.Improve coding style. For example: remove space between @param. In V1: Provides library functions for common SMBIOS operations. Only available t= o DXE and UEFI module types. Signed-off-by: Duke Zhai Cc: Eric Xing Cc: Ken Yao Cc: Igniculus Fu Cc: Abner Chang --- .../Include/Library/SmbiosLib.h | 171 ++++++++++ .../Library/SmbiosLib/SmbiosLib.c | 322 ++++++++++++++++++ .../Library/SmbiosLib/SmbiosLib.inf | 41 +++ 3 files changed, 534 insertions(+) create mode 100644 Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Include/Libr= ary/SmbiosLib.h create mode 100644 Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Library/Smbi= osLib/SmbiosLib.c create mode 100644 Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Library/Smbi= osLib/SmbiosLib.inf diff --git a/Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Include/Library/Smb= iosLib.h b/Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Include/Library/Smbio= sLib.h new file mode 100644 index 0000000000..53e8652686 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Include/Library/SmbiosLib.= h @@ -0,0 +1,171 @@ +/** @file + Implements AMD SmbiosLib.h + Provides library functions for common SMBIOS operations. Only available = to DXE + and UEFI module types. + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ Copyright (c) 2012, Apple Inc. All rights reserved. All rights reserved.=
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SMBIOS_LIB_H_ +#define SMBIOS_LIB_H_ + +#include +#include + +/// +/// Cache copy of the SMBIOS Protocol pointer +/// +extern EFI_SMBIOS_PROTOCOL *gSmbios; + +/// +/// Template for SMBIOS table initialization. +/// The SMBIOS_TABLE_STRING types in the formated area must match the +/// StringArray sequene. +/// +typedef struct { + // + // formatted area of a given SMBIOS record + // + SMBIOS_STRUCTURE *Entry; + // + // NULL terminated array of ASCII strings to be added to the SMBIOS reco= rd. + // + CHAR8 **StringArray; +} SMBIOS_TEMPLATE_ENTRY; + +/** + Create an initial SMBIOS Table from an array of SMBIOS_TEMPLATE_ENTRY + entries. SMBIOS_TEMPLATE_ENTRY.NULL indicates the end of the table. + + @param[in] Template Array of SMBIOS_TEMPLATE_ENTRY entries. + + @retval EFI_SUCCESS New SMBIOS tables were created. + @retval EFI_OUT_OF_RESOURCES New SMBIOS tables were not created. +**/ +EFI_STATUS +EFIAPI +SmbiosLibInitializeFromTemplate ( + IN SMBIOS_TEMPLATE_ENTRY *Template + ); + +/** + Create SMBIOS record. + + Converts a fixed SMBIOS structure and an array of pointers to strings in= to + an SMBIOS record where the strings are cat'ed on the end of the fixed re= cord + and terminated via a double NULL and add to SMBIOS table. + + @param[in] SmbiosEntry Fixed SMBIOS structure + @param[in] StringArray Array of strings to convert to an SMBIOS strin= g pack. + NULL is OK. + + @retval EFI_SUCCESS New SmbiosEntry was added to SMBIOS table. + @retval EFI_OUT_OF_RESOURCES SmbiosEntry was not added. +**/ +EFI_STATUS +EFIAPI +SmbiosLibCreateEntry ( + IN SMBIOS_STRUCTURE *SmbiosEntry, + IN CHAR8 **StringArray + ); + +/** + Update the string associated with an existing SMBIOS record. + + This function allows the update of specific SMBIOS strings. The number o= f valid strings for any + SMBIOS record is defined by how many strings were present when Add() was= called. + + @param[in] SmbiosHandle SMBIOS Handle of structure that will have = its string updated. + @param[in] StringNumber The non-zero string number of the string t= o update. + @param[in] String Update the StringNumber string with String= . + + @retval EFI_SUCCESS SmbiosHandle had its StringNumber String u= pdated. + @retval EFI_INVALID_PARAMETER SmbiosHandle does not exist. Or String is = invalid. + @retval EFI_UNSUPPORTED String was not added because it is longer = than the SMBIOS Table supports. + @retval EFI_NOT_FOUND The StringNumber.is not valid for this SMB= IOS record. +**/ +EFI_STATUS +EFIAPI +SmbiosLibUpdateString ( + IN EFI_SMBIOS_HANDLE SmbiosHandle, + IN SMBIOS_TABLE_STRING StringNumber, + IN CHAR8 *String + ); + +/** + Update the string associated with an existing SMBIOS record. + + This function allows the update of specific SMBIOS strings. The number o= f valid strings for any + SMBIOS record is defined by how many strings were present when Add() was= called. + + @param[in] SmbiosHandle SMBIOS Handle of structure that will have = its string updated. + @param[in] StringNumber The non-zero string number of the string t= o update. + @param[in] String Update the StringNumber string with String= . + + @retval EFI_SUCCESS SmbiosHandle had its StringNumber String u= pdated. + @retval EFI_INVALID_PARAMETER SmbiosHandle does not exist. Or String is = invalid. + @retval EFI_UNSUPPORTED String was not added because it is longer = than the SMBIOS Table supports. + @retval EFI_NOT_FOUND The StringNumber.is not valid for this SMB= IOS record. +**/ +EFI_STATUS +EFIAPI +SmbiosLibUpdateUnicodeString ( + IN EFI_SMBIOS_HANDLE SmbiosHandle, + IN SMBIOS_TABLE_STRING StringNumber, + IN CHAR16 *String + ); + +/** + Allow caller to read a specific SMBIOS string + + @param[in] Header SMBIOS record that contains the string. + @param[in[ StringNumber Instance of SMBIOS string 1 - N. + + @retval NULL Instance of Type SMBIOS string was not fou= nd. + @retval Other Pointer to matching SMBIOS string. +**/ +CHAR8 * +EFIAPI +SmbiosLibReadString ( + IN SMBIOS_STRUCTURE *Header, + IN EFI_SMBIOS_STRING StringNumber + ); + +/** + Allow the caller to discover a specific SMBIOS entry, and patch it if ne= cissary. + + @param[in] Type Type of the next SMBIOS record to return. + @param[in[ Instance Instance of SMBIOS record 0 - N-1. + @param[out] SmbiosHandle Returns SMBIOS handle for the matching rec= ord. + + @retval NULL Instance of Type SMBIOS record was not fou= nd. + @retval Other Pointer to matching SMBIOS record. +**/ +SMBIOS_STRUCTURE * +EFIAPI +SmbiosLibGetRecord ( + IN EFI_SMBIOS_TYPE Type, + IN UINTN Instance, + OUT EFI_SMBIOS_HANDLE *SmbiosHandle + ); + +/** + Remove an SMBIOS record. + + This function removes an SMBIOS record using the handle specified by Smb= iosHandle. + + @param[in] SmbiosHandle The handle of the SMBIOS record to rem= ove. + + @retval EFI_SUCCESS SMBIOS record was removed. + @retval EFI_INVALID_PARAMETER SmbiosHandle does not specify a valid = SMBIOS record. +**/ +EFI_STATUS +EFIAPI +SmbiosLibRemove ( + OUT EFI_SMBIOS_HANDLE SmbiosHandle + ); + +#endif diff --git a/Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Library/SmbiosLib/S= mbiosLib.c b/Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Library/SmbiosLib/S= mbiosLib.c new file mode 100644 index 0000000000..52d5e2d131 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Library/SmbiosLib/SmbiosLi= b.c @@ -0,0 +1,322 @@ +/** @file + Provides library functions for common SMBIOS operations. Only available = to DXE + and UEFI module types. + +Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+Copyright (c) 2012, Apple Inc. All rights reserved. +Portitions Copyright (c) 2006 - 2019, Intel Corporation. All rights reserv= ed.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +EFI_SMBIOS_PROTOCOL *gSmbios =3D NULL; + +/** + Create an initial SMBIOS Table from an array of SMBIOS_TEMPLATE_ENTRY + entries. SMBIOS_TEMPLATE_ENTRY.NULL indicates the end of the table. + + @param[in] Template Array of SMBIOS_TEMPLATE_ENTRY entries. + + @retval EFI_SUCCESS New SMBIOS tables were created. + @retval EFI_OUT_OF_RESOURCES New SMBIOS tables were not created. +**/ +EFI_STATUS +EFIAPI +SmbiosLibInitializeFromTemplate ( + IN SMBIOS_TEMPLATE_ENTRY *Template + ) +{ + EFI_STATUS Status; + UINTN Index; + + if (Template =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Status =3D EFI_SUCCESS; + + for (Index =3D 0; Template[Index].Entry !=3D NULL; Index++) { + Status =3D SmbiosLibCreateEntry (Template[Index].Entry, Template[Index= ].StringArray); + } + + return Status; +} + +/** + Create SMBIOS record. + + @param[in] SmbiosEntry Fixed SMBIOS structure + @param[in] StringArray Array of strings to convert to an SMBIOS strin= g pack. + NULL is OK. + + @return Return the status form gSmbios->Add. + @retval EFI_OUT_OF_RESOURCES New SMBIOS tables were not created. +**/ +EFI_STATUS +EFIAPI +SmbiosLibCreateEntry ( + IN SMBIOS_STRUCTURE *SmbiosEntry, + IN CHAR8 **StringArray + ) +{ + EFI_STATUS Status; + EFI_SMBIOS_HANDLE SmbiosHandle; + EFI_SMBIOS_TABLE_HEADER *Record; + UINTN Index; + UINTN StringSize; + UINTN Size; + CHAR8 *Str; + + // Calculate the size of the fixed record and optional string pack + Size =3D SmbiosEntry->Length; + if (StringArray =3D=3D NULL) { + Size +=3D 2; // Min string section is double null + } else if (StringArray[0] =3D=3D NULL) { + Size +=3D 2; // Min string section is double null + } else { + for (Index =3D 0; StringArray[Index] !=3D NULL; Index++) { + StringSize =3D AsciiStrSize (StringArray[Index]); + Size +=3D StringSize; + } + + // Don't forget the terminating double null + Size +=3D 1; + } + + // Copy over Template + Record =3D (EFI_SMBIOS_TABLE_HEADER *)AllocateZeroPool (Size); + if (Record =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CopyMem (Record, SmbiosEntry, SmbiosEntry->Length); + + if (StringArray !=3D NULL) { + // Append string pack + Str =3D ((CHAR8 *)Record) + Record->Length; + for (Index =3D 0; StringArray[Index] !=3D NULL; Index++) { + StringSize =3D AsciiStrSize (StringArray[Index]); + CopyMem (Str, StringArray[Index], StringSize); + Str +=3D StringSize; + } + + *Str =3D 0; + } + + SmbiosHandle =3D SMBIOS_HANDLE_PI_RESERVED; + Status =3D gSmbios->Add ( + gSmbios, + gImageHandle, + &SmbiosHandle, + Record + ); + + FreePool (Record); + return Status; +} + +/** + Update the string associated with an existing SMBIOS record. + + This function allows the update of specific SMBIOS strings. The number o= f valid strings for any + SMBIOS record is defined by how many strings were present when Add() was= called. + + @param[in] SmbiosHandle SMBIOS Handle of structure that will have = its string updated. + @param[in] StringNumber The non-zero string number of the string t= o update. + @param[in] String Update the StringNumber string with String= . + + @retval EFI_SUCCESS SmbiosHandle had its StringNumber String u= pdated. + @retval EFI_INVALID_PARAMETER SmbiosHandle does not exist. Or String is = invalid. + @retval EFI_UNSUPPORTED String was not added because it is longer = than the SMBIOS Table supports. + @retval EFI_NOT_FOUND The StringNumber.is not valid for this SMB= IOS record. +**/ +EFI_STATUS +EFIAPI +SmbiosLibUpdateString ( + IN EFI_SMBIOS_HANDLE SmbiosHandle, + IN SMBIOS_TABLE_STRING StringNumber, + IN CHAR8 *String + ) +{ + UINTN StringIndex; + + if (String =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (*String =3D=3D '\0') { + // A string with no data is not legal in SMBIOS + return EFI_INVALID_PARAMETER; + } + + StringIndex =3D StringNumber; + return gSmbios->UpdateString (gSmbios, &SmbiosHandle, &StringIndex, Stri= ng); +} + +/** + Update the string associated with an existing SMBIOS record. + + This function allows the update of specific SMBIOS strings. The number o= f valid strings for any + SMBIOS record is defined by how many strings were present when Add() was= called. + + @param[in] SmbiosHandle SMBIOS Handle of structure that will have = its string updated. + @param[in] StringNumber The non-zero string number of the string t= o update. + @param[in] String Update the StringNumber string with String= . + + @retval EFI_SUCCESS SmbiosHandle had its StringNumber String u= pdated. + @retval EFI_INVALID_PARAMETER SmbiosHandle does not exist. Or String is = invalid. + @retval EFI_UNSUPPORTED String was not added because it is longer = than the SMBIOS Table supports. + @retval EFI_NOT_FOUND The StringNumber.is not valid for this SMB= IOS record. +**/ +EFI_STATUS +EFIAPI +SmbiosLibUpdateUnicodeString ( + IN EFI_SMBIOS_HANDLE SmbiosHandle, + IN SMBIOS_TABLE_STRING StringNumber, + IN CHAR16 *String + ) +{ + EFI_STATUS Status; + UINTN StringIndex; + CHAR8 *Ascii; + + if (String =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (*String =3D=3D '\0') { + // A string with no data is not legal in SMBIOS + return EFI_INVALID_PARAMETER; + } + + Ascii =3D AllocateZeroPool (StrSize (String)); + if (Ascii =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + UnicodeStrToAsciiStrS (String, Ascii, StrSize (String)); + + StringIndex =3D StringNumber; + Status =3D gSmbios->UpdateString (gSmbios, &SmbiosHandle, &StringIn= dex, Ascii); + + FreePool (Ascii); + return Status; +} + +/** + Allow caller to read a specific SMBIOS string + + @param[in] Header SMBIOS record that contains the string. + @param[in[ StringNumber Instance of SMBIOS string 1 - N. + + @retval NULL Instance of Type SMBIOS string was not fou= nd. + @retval Other Pointer to matching SMBIOS string. +**/ +CHAR8 * +EFIAPI +SmbiosLibReadString ( + IN SMBIOS_STRUCTURE *Header, + IN EFI_SMBIOS_STRING StringNumber + ) +{ + CHAR8 *Data; + UINTN Match; + + Data =3D (CHAR8 *)Header + Header->Length; + for (Match =3D 1; !(*Data =3D=3D 0 && *(Data+1) =3D=3D 0); ) { + if (StringNumber =3D=3D Match) { + return Data; + } + + Data++; + if (*(Data - 1) =3D=3D '\0') { + Match++; + } + } + + return NULL; +} + +/** + Allow the caller to discover a specific SMBIOS entry, and patch it if ne= cissary. + + @param[in] Type Type of the next SMBIOS record to return. + @param[in[ Instance Instance of SMBIOS record 0 - N-1. + @param[out] SmbiosHandle Returns SMBIOS handle for the matching rec= ord. + + @retval NULL Instance of Type SMBIOS record was not fou= nd. + @retval Other Pointer to matching SMBIOS record. +**/ +SMBIOS_STRUCTURE * +EFIAPI +SmbiosLibGetRecord ( + IN EFI_SMBIOS_TYPE Type, + IN UINTN Instance, + OUT EFI_SMBIOS_HANDLE *SmbiosHandle + ) +{ + EFI_STATUS Status; + EFI_SMBIOS_TABLE_HEADER *Record; + UINTN Match; + + Match =3D 0; + *SmbiosHandle =3D SMBIOS_HANDLE_PI_RESERVED; + do { + Status =3D gSmbios->GetNext (gSmbios, SmbiosHandle, &Type, &Record, NU= LL); + if (!EFI_ERROR (Status)) { + if (Match =3D=3D Instance) { + return (SMBIOS_STRUCTURE *)Record; + } + + Match++; + } + } while (!EFI_ERROR (Status)); + + return NULL; +} + +/** + Remove an SMBIOS record. + + This function removes an SMBIOS record using the handle specified by Smb= iosHandle. + + @param[in] SmbiosHandle The handle of the SMBIOS record to rem= ove. + + @retval EFI_SUCCESS SMBIOS record was removed. + @retval EFI_INVALID_PARAMETER SmbiosHandle does not specify a valid = SMBIOS record. +**/ +EFI_STATUS +EFIAPI +SmbiosLibRemove ( + OUT EFI_SMBIOS_HANDLE SmbiosHandle + ) +{ + return gSmbios->Remove (gSmbios, SmbiosHandle); +} + +/** + + @param[in] ImageHandle ImageHandle of the loaded driver. + @param[in] SystemTable Pointer to the EFI System Table. + + @retval EFI_SUCCESS Register successfully. + @retval EFI_OUT_OF_RESOURCES No enough memory to register this handle= r. +**/ +EFI_STATUS +EFIAPI +SmbiosLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&gSm= bios); +} diff --git a/Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Library/SmbiosLib/S= mbiosLib.inf b/Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Library/SmbiosLib= /SmbiosLib.inf new file mode 100644 index 0000000000..c1829d6f2d --- /dev/null +++ b/Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Library/SmbiosLib/SmbiosLi= b.inf @@ -0,0 +1,41 @@ +# SMBIOS Library +# +# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+# Copyright (c) 2012, Apple Inc. All rights reserved. +# Portions copyright (c) 2006 - 2010, Intel Copyright (c) 2006 - 2018, Int= el Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SmbiosLib + FILE_GUID =3D 56E8FB13-C554-F864-E3D1-9A0EAC76F867 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SmbiosLib|DXE_CORE DXE_DRIVER DXE_RUN= TIME_DRIVER DXE_SMM_DRIVER SMM_CORE UEFI_APPLICATION UEFI_DRIVER + + CONSTRUCTOR =3D SmbiosLibConstructor + + +[Sources] + SmbiosLib.c + +[Packages] + MdePkg/MdePkg.dec + VanGoghCommonPkg/AmdCommonPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + UefiBootServicesTableLib + UefiLib + +[Protocols] + gEfiSmbiosProtocolGuid + +[Depex] + gEfiSmbiosProtocolGuid --=20 2.31.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114590): https://edk2.groups.io/g/devel/message/114590 Mute This Topic: https://groups.io/mt/103975456/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-