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 38DCF9412D2 for ; Fri, 26 Jan 2024 06:02:36 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=9FNzQ3TjNnoa2+QfdyDNwFJCTACKg1vwDueyzs8zoCw=; 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=1706248954; v=1; b=LEGbN4DEUqrV4xMpUrQPmJ4XfB0ZM/IfVxFPHcuPeNjtrVjNGpAzyfjEwAZsjaGJDTfGX7Nq KPFmbnUUJ6CkemE/jH/jXIidk267QyBpZe8a93ZGezX4I5rpFnj9wOG5n1ewbquEi2+v7bIECcZ SZLj8YADRCr+CyR/kNIoueNU= X-Received: by 127.0.0.2 with SMTP id Y4I3YY7687511x2sA3qcnzOi; Thu, 25 Jan 2024 22:02:34 -0800 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.52]) by mx.groups.io with SMTP id smtpd.web10.9832.1706248952461654427 for ; Thu, 25 Jan 2024 22:02:32 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FqIxNbDJByZsfX8lJ9Ce223GX5YyU79kTfGHIxVL8+sUl2fWukK/Tfuovyi7QVvYaXJ4No+b/8THu/TN5N+xKbr+3V2wYn/Hf1q1qU8Mm8AxShcGC8t7MYhkNQJrdNCs1a2/TZ8AqwXKX27HZVNu8iaOAJD/K6TYKFh3W2/mWIWW/85MzXsX4LK0QjYQRiARYeCsSe88nKaUE9CkRbwYoqKg/R6wZpG8nJe+SodDPjTecSgnyCBSBNF5Q2sC11K1S58Hlau+CFB4bEbbwGV4FrULLOnRsqczd/PJW0edBIN7B34w70ZeHdt5xClwa8GoM/Rt4idO/wvG8WQhBeI6wQ== 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=dX+6fHBVHCgQzYufJ2lnRIMsB0xeaU0W/4uz/N7CrTo=; b=PPy4xHRI9n6Nb9mrCImdAH3DWC/Wk+CWzcEmBCaXlFHIacBI0mQGUDqk4SDUfNU3yQ0yXeaSaY3B9WFba/voBk/rTkXcMYcXjX1nZB7zB0XyQKpxUaX5g3T33hXk5hq5WUUzV02iXoA8zdw5UufiTPYif1XdF5qKkiYotunUhvBhKSL+2F6LjoGCydCFsy26rLMxFmaYmXytAEKdZG05J6RTtc0yFj0iN2K+YZ2WgUZCVLldrVJHwEkus8pvxoB0oE1YC50duAABibCistrQrQk8y+/xJn20r4zYBRV2VFxn5PsPnK3ByP4oDnZcz7vKYGu4cjo9guI7mKjSE10D3Q== 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 CH2PR12CA0019.namprd12.prod.outlook.com (2603:10b6:610:57::29) by PH7PR12MB9253.namprd12.prod.outlook.com (2603:10b6:510:30d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Fri, 26 Jan 2024 06:02:29 +0000 X-Received: from DS2PEPF0000343D.namprd02.prod.outlook.com (2603:10b6:610:57:cafe::3d) by CH2PR12CA0019.outlook.office365.com (2603:10b6:610:57::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.26 via Frontend Transport; Fri, 26 Jan 2024 06:02:28 +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 DS2PEPF0000343D.mail.protection.outlook.com (10.167.18.40) 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 06:02:28 +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 00:02:26 -0600 From: "Zhai, MingXin (Duke) via groups.io" To: CC: Eric Xing , Ken Yao , Igniculus Fu , Abner Chang Subject: [edk2-devel] [PATCH V2 14/32] AMD/VanGoghBoard: Check in SmbiosLib Date: Fri, 26 Jan 2024 14:00:32 +0800 Message-ID: <20240126060050.1725-15-duke.zhai@amd.com> In-Reply-To: <20240126060050.1725-1-duke.zhai@amd.com> References: <20240126060050.1725-1-duke.zhai@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF0000343D:EE_|PH7PR12MB9253:EE_ X-MS-Office365-Filtering-Correlation-Id: bfd53b56-553c-4279-aed6-08dc1e346087 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: gSlKMKaoYY8V/z6iYldP/k1TeuVuhcjzsoN8CeVPQrbjsPX/JT72thqzuj5JmseEpV0cui+yoqJjxAoLKBgvWnqjz7cCSBlEKSO2XrDDEhULRu+HvgaSKWRYkPBrBcH8KC82M3KMoIzB0s0xk554V2yPOw/+iKAz+jk5YiFkCAYsVXyr6JpGyy4i0609oliqB33T48kkBSUutyieah6nS0Y9HWQlE7BIpUO8kgu8aFINjv8oyPmJaWy423wd+cDl5vjzLy5iMHpxISZscB6gKSpZf/2SWCwUKuBvVFbqS5sL1w5w7lFoOebRChQmfHBY3df2YnqsF2lCeL6iu6kTo9hBDdf0fchLn0K07HyVpG2UDh1sfVuZKMLEPtJ+hG+YmCBdi5INf1eWkXStl+fOcMeznYLP97YLyXzQgVHLA502V2VjZIQq0TavK7HnuJ7UKauGmuosSh+L3S8dsI3M5X7ue5zF9pq8YRallDWjfa2uj/63ZZDA1b1ItEjGRKdCqtDrqwaouB3HYXQb2GhwxK4m9qrfQLF1NQ9oyDNlHmHtffkSsGqn5T+Il2mHbN9FDKoekN37p5HGr8w+4/ErC2DyphVUs54tigWqqHKuK99/XUfRfg7QAhYVRLUL2B8FzTrSqkJPU/9HhGxqq8pPXWqUJvv0SgK6K7NJJIX2ojqlWHZ1jvY0zyJioNukDRZtnds5KEdTKI8g3xpoxO4pcqf5rZY3dPwYRVx/HgJwdas92toN0yR37KXswl5V3XRqArNzE7t9bK3ZBJw8WiRG0Q== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 06:02:28.5624 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bfd53b56-553c-4279-aed6-08dc1e346087 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: DS2PEPF0000343D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9253 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: i0Dewb3dUyurTcF1JExZ1TiRx7686176AA= 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=LEGbN4DE; 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 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..314f0448fd --- /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 -- 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 (#114508): https://edk2.groups.io/g/devel/message/114508 Mute This Topic: https://groups.io/mt/103971405/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-