From nobody Mon Sep 16 20:01:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+114062+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1705676243191617.5887850706614; Fri, 19 Jan 2024 06:57:23 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=qq5iVCKRrtkDktzZmpXwQSbDrMxKcnp0DQFuYI3MK+c=; 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=1705676242; v=1; b=HydCw/6I9Vi+D7T7K4g54i80zE0oxSeG/pZKPfzwL+KIw2Xg9Foe0D+6Y0Gz6aj3uROsV94v Lxnw/alpwz+Wmap0g2njzgCsynd+ahpWndRn0Qju+jSRtVslrZkcgx5EQM6T9TubzYviyeK4iyH NMXrSo5dutTeMlpC7o4TLQxU= X-Received: by 127.0.0.2 with SMTP id L0q2YY1788612xgYYC64g8KG; Fri, 19 Jan 2024 06:57:22 -0800 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.80]) by mx.groups.io with SMTP id smtpd.web11.5899.1705560711996811662 for ; Wed, 17 Jan 2024 22:51:52 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I1ed/vVQqI4XGkMakDqYCkCrbtJgjWfaIqN+qX95eFsijLAYUm+GRODEcpMUIqbcemaxqJgaboq/BRA09mb3Np8y9aK6FVmxYVcgm7hgDnefKhR+/cmwSxf8I252kwCwyhytjaoUYz/1hn1Lb+XG7IfSp9hwiaXidrffoaPg1WPN+Ev3NF9PpY9wuTz77k+UEFM8EW/ziOW05xcSB1CFmHK8TBPac0gh9aF3XkIpEShPxBS5XUgvobQMDh+c3ruNT9yZTTYC0YcGMISsddOIai3UXjuVormy2Ys3eZ2GrksN4OBNA8dGEK+mjKBjkyg/YH0zgooX658UDrt2xOrn/Q== 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=8yyYc20vooJtfgHKOFRQ6qh/CZll1niukCRDkAeFzxw=; b=Dh2Kl94iimZlCUoAjYe7YJh2ARMgjnsyPFIHTrZU5bBfOgC48eGq7MWRkyH2MsQJih/XTQa2uxalqPB1I/7EYDLTxuHQC1cPNE/XofSpLZoKrtOLUyR14LTGWP0XrUi9uDWL3yKm87ntxS1UTBPAit/GhxkE03eOrOlwX/Gi9mQkKYB5I1zO3JdHxxxvRscqz3M4iY0IaNzT6GHdOX+sGd0oyj2ILq42c97aqnN/1oFV0EHtiWNegkZh74wduCpXvO+h5ZiuEnwUmdAIa/LIqI8Ns6ffiD0xbsIq3eZYgAsAjG7cEbP9HACcyNqQVcUE5MCCnbDC/hUl0IH/UYxC5A== 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 CY5PR22CA0032.namprd22.prod.outlook.com (2603:10b6:930:1d::20) by LV3PR12MB9166.namprd12.prod.outlook.com (2603:10b6:408:19c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.19; Thu, 18 Jan 2024 06:51:49 +0000 X-Received: from CY4PEPF0000E9D8.namprd05.prod.outlook.com (2603:10b6:930:1d:cafe::e0) by CY5PR22CA0032.outlook.office365.com (2603:10b6:930:1d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.24 via Frontend Transport; Thu, 18 Jan 2024 06:51:49 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+114062+1787277+3901457@groups.io; helo=mail02.groups.io; 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 CY4PEPF0000E9D8.mail.protection.outlook.com (10.167.241.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7181.14 via Frontend Transport; Thu, 18 Jan 2024 06:51:48 +0000 X-Received: from SATLEXMB06.amd.com (10.181.40.147) 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; Thu, 18 Jan 2024 00:51:47 -0600 X-Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 18 Jan 2024 00:51:15 -0600 X-Received: from SHA-LX-MINGXZHA.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.34 via Frontend Transport; Thu, 18 Jan 2024 00:51:13 -0600 From: "duke.zhai via groups.io" To: CC: Eric Xing , Ken Yao , Igniculus Fu , Abner Chang Subject: [edk2-devel] [PATCH 14/33] AMD/VanGoghBoard: Check in SmbiosLib Date: Thu, 18 Jan 2024 14:50:27 +0800 Message-ID: <20240118065046.961-15-duke.zhai@amd.com> In-Reply-To: <20240118065046.961-1-duke.zhai@amd.com> References: <20240118065046.961-1-duke.zhai@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D8:EE_|LV3PR12MB9166:EE_ X-MS-Office365-Filtering-Correlation-Id: aac48d10-3c0a-438c-e8b0-08dc17f1f1c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: FWS61WN1KhJe4A63MrKp4X/hfQM2VpvrDlP84WFiZKhKe17kx4oIYbVQTgc7vWepDLAGp4FI4LjUgsCq6lBXQyJxsYHdCARA0lQo48j2NHUqi0UrWczm1om7aybHKsapv5rlN3bpcCi+lkvI7JmwR2+ktxJ+bEWhBseK89tEGc2RF9qB/3e2kkZIwdXMkK3YTmzLIvXwsB3QuJfdhPk0NxdWNnvda537W4KwoclRqjh1OACyAPKDhqlJyt1VAU/L+wq+JDo1yh47PAaj5jT64zkPEREp32z02c8N++RRJOtAw8jMCCq+tS6nr790DmPnSj6ut6rQE8rMmMAVHqK9oV/uzfimhP53nWL0m7zDOZ82upIYFTlg9fIjjbL54WQhDN8+qECFuDmT+999ornunnrJRPZavpc9WvTcq5UMnctUUOTsrYtmAijQFjAxXx0jMknzFFAJoui2BY1P3UwLU+mFk9aLbteSixfhzHBhWWGiILeR1zdJqqaDWKWz0RN+QEVDXtIDqa2HGhx0OVsTtSwPpM2OgzaMX3wxBSIkqFfk0j31KlWU9ps7VjokGz/Tx3xfpcuCEn6yUNJ8dAJ0V1zkqFPOtWMjKMHT1WuJkftbLvT8Kvi/1imfQzrFKB7kIwT338IIeqek8Vjfn+h5FyAu2Rcy3DCSgHM9cCB15rUHM0F8xjoSg3z3aM+p+//vAucqsgPU1NXH6UghpsLP7mGxN/Gp8EIK5RRoTEsEeKyJ3r4OIS5c+IJ2GGcHjQeVxXIcMozvymjrWHON77cu3g== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2024 06:51:48.9707 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aac48d10-3c0a-438c-e8b0-08dc17f1f1c8 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: CY4PEPF0000E9D8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9166 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: Cv2gz2mqJTnp9yuOsoOuNJU7x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705676244955100055 Content-Type: text/plain; charset="utf-8" From: Duke Zhai BZ #:4640 Provides library functions for common SMBIOS operations. Only available to = 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 | 179 ++++++++++ .../Library/SmbiosLib/SmbiosLib.c | 332 ++++++++++++++++++ .../Library/SmbiosLib/SmbiosLib.inf | 51 +++ 3 files changed, 562 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..5880eac36e --- /dev/null +++ b/Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Include/Library/SmbiosLib.h @@ -0,0 +1,179 @@ +/** @file + Implements AMD SmbiosLib.h + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +// This file includes code originally published under the following licens= e. +/** @file + Provides library functions for common SMBIOS operations. Only available = to DXE + and UEFI module types. + + +Copyright (c) 2012, Apple Inc. All rights reserved. +Portitions Copyright (c) 2006 - 2011, Intel Corporation. All rights reserv= ed.
+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..97a45c286d --- /dev/null +++ b/Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Library/SmbiosLib/SmbiosLi= b.c @@ -0,0 +1,332 @@ +/** @file + Implements AMD Smbioslib.c + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +/* This file includes code originally published under the following licens= e. */ + +/** @file + Provides library functions for common SMBIOS operations. Only available = to DXE + and UEFI module types. + + +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..4ed4691b36 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/VanGoghCommonPkg/Library/SmbiosLib/SmbiosLi= b.inf @@ -0,0 +1,51 @@ +## @file +# SMBIOS Library +# +# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +## @file +# This file includes code originally published under the following license. +# SMBIOS Library +# +# 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 (#114062): https://edk2.groups.io/g/devel/message/114062 Mute This Topic: https://groups.io/mt/103831174/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-