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 2D25F941C9B for ; Tue, 25 Jul 2023 23:38:41 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=81IDJzWonYEbh078wv2LrDwVPlFcTsds+KkwyVXe2/g=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:X-Received:X-Received:X-MS-Exchange-Authentication-Results:Received-SPF:X-Received:X-Received:X-Received:X-Received:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:X-NVConfidentiality:X-NV-OnPremToCloud:X-EOPAttributedMessage:X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam-Message-Info:X-OriginatorOrg:X-MS-Exchange-CrossTenant-OriginalArrivalTime:X-MS-Exchange-CrossTenant-Network-Message-Id:X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp:X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs:X-MS-Exchange-CrossTenant-FromEntityHeader:X-MS-Exchange-Transport-CrossTenantHeadersStamped:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscrib e:X-Gm-Message-State:Content-Type:Content-Transfer-Encoding; s=20140610; t=1690328319; v=1; b=pdiO7NdxNKySONe8Pxoqgjx7OttIlMR2o+v/Wh0HsNKHKwry0M+mH05MGaxxDPt/+irlBUWB sdULBQutlqrATG8y4z0E/09L47Edu9ug0+NJZP2Fmgq2WoS95b2Hsi3VBvrbi8FFvAZ5R4/bMet RhDm5iAei/Cvsfengdolyoh0= X-Received: by 127.0.0.2 with SMTP id 0lX9YY7687511xmJoq2pyHFC; Tue, 25 Jul 2023 16:38:39 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.53]) by mx.groups.io with SMTP id smtpd.web11.105.1690328319033693234 for ; Tue, 25 Jul 2023 16:38:39 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CCohCnBk1mX6zMHSmenpDIWDGlxgxS8OoVCjkCjvYbxm+WrQHgVjnx1v/i9PFZEFUMiCcsQG2NZuHPZR73PvppKFIX08E8HXg/se7ROH+z8pklfUkgj/YmWzoSfZ8z+YNbvYRGooGRLUZaJmtnWSGLD2OCwGY3T0dswWFMnUYZjRItvda7i/apBqK9YHhvpAmPHXJUwdGL4Tg7P3gJWr50j8RfSI/h2pe6Bq67Ugtnw3gCmI9l2XwLUmlJTIqNziT4B0yUO9L+FEYa5U/+sa7iQZUOTWmvGf+PqXGhaSv3ZtuKqASuxgc+Vic1tkRpmucdLWL4fwkjGR0VrHGATp5w== 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=7OKRnISpiXFMRS2Mdk/DO1Ng/UX5WOQdWCc6ZnCmpM8=; b=KAVTYeC5MJOM3W3ev5MAyXFTyBcH6MsBPnbXkkJT2LyHEHvlZPOntlt3nrckiC/XfY4Ou1rz84ZK9g5YMGRcvtg0tdkayqB0HzglVx98VKhisPRrs8esCNCWJAkWG70fofbSVp8OXpO/wFNBYNTXUk03XPIGNKulESSDzhDCNDYoZqp4b+YuYmjYhIlnwUTf7lFF/x/ZZFEDQjz/J5RcFrNjTWapK4TBhpoUwHLudPBXO61iDlTOs7O6NG7VCd+EhL/WiOuXcQvJYOq7OBFEyVEfuuvNqFqkkWBkwy+ZXR1XfdDWMgFvw3eIcsWG1amXswsU2KEmwtAA+r0zf4+72Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none X-Received: from MW4PR04CA0350.namprd04.prod.outlook.com (2603:10b6:303:8a::25) by IA0PR12MB7673.namprd12.prod.outlook.com (2603:10b6:208:435::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 23:38:35 +0000 X-Received: from CO1NAM11FT111.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8a:cafe::71) by MW4PR04CA0350.outlook.office365.com (2603:10b6:303:8a::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33 via Frontend Transport; Tue, 25 Jul 2023 23:38:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (216.228.117.161) by CO1NAM11FT111.mail.protection.outlook.com (10.13.174.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Tue, 25 Jul 2023 23:38:35 +0000 X-Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 25 Jul 2023 16:38:22 -0700 X-Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 25 Jul 2023 16:38:22 -0700 X-Received: from build-gmahadevan-20230109T020417557.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 25 Jul 2023 16:38:22 -0700 From: "Girish Mahadevan via groups.io" To: , CC: , , , , , Subject: [edk2-devel] [PATCH v3 1/5] DynamicTablesPkg: Add SMBIOS table generation Date: Tue, 25 Jul 2023 23:38:01 +0000 Message-ID: <20230725233805.646668-2-gmahadevan@nvidia.com> In-Reply-To: <20230725233805.646668-1-gmahadevan@nvidia.com> References: <20230725233805.646668-1-gmahadevan@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT111:EE_|IA0PR12MB7673:EE_ X-MS-Office365-Filtering-Correlation-Id: 8e9eb5fe-9065-45f2-64ff-08db8d68438a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: Nm7tVifVVXgK1fC7Vg6HF92Z0RQGvQnm6/jpWkZRO+79Bzyn7MIzIXj1yjE12RO2sLdSlG8fZuCai32EwhUGHZvkp0Ma55W0T6+NqlPcDzDnCoIehvoiqUMgYb7JfHhKFdEOe9XBpMs5bHJSJ/UVose0pGCeH0Xt1uqUCe973C34EIggtzQpdM0cVRdODyPSDyP9lUS3pF6wqIdDGNTLHt6DBHcL5ZIXRbGf/Zq7a/XL0XhxFF8dC0qoojvO8lPQ4ZVQEe7ZiIwnIZi5hQOjLV19N5EyvKaiVRxBAX5KYnsaRQotokMhDKwkF+z4zA+7DDKUfGWUr7TxKVN/ZPxs/2IDWnN7dlI/ijOiq/8UFw23+VpOHy0oXCGohGfT3+qq2wioh2zR6BOnMW51Rw2Y8wLKI+GFJYqMO652LkuikgVpDPPlUE73xRpN/p7Z/jq/deMcBAYzKuMiiYGZhlo8nlxgC779Z+8z9ZdhM7rHv8wgZR/LJ2vRUeh4i/TH7uG1tR1uC7iNc9AEMjfzp6CHMMmlpkajSPaBaJp+1FnS2EPsEpfFda+7HKeufmYnF/g46/6blxfK7t+y9q5zdGKoei8Z5BAqvLxavbn+4AGRjXz6Scsz94yiksZk/GNOMdAHj1Zv9PjLoWFrG6+aSTSsZgXgNk4gYXQI+6Vzf9iJxpIc1qqMIWL8d6TuAVfDT/AOPOacG4bx1dnLZ7JvO68uvLKDsk+TB5q/UgwM/RSRRO2LykDL5JNx1Jctn3bSHNHQ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 23:38:35.0753 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8e9eb5fe-9065-45f2-64ff-08db8d68438a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT111.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7673 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,gmahadevan@nvidia.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: jPdWzrF7Dv4k440W1nCngKLDx7686176AA= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=pdiO7Ndx; 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 Add the SMBIOS Table generator code to the DynamicTablesPkg. This change includes adding new logic to the DynamicTableManager to process and add SMBIOS tables and augmenting the existing SMBIOS Factory generator to include installing multiple SMBIOS tables . Also included is running the SMBIOS and ACPI table generation as part of the SMBIOS and ACPI protocol GUID callback notifications respectively. Change-Id: Icc090108c16e87657260af6daf856f3d69b602e3 Signed-off-by: Girish Mahadevan Reviewed-by: Jeff Brasen --- .../DynamicTableFactory.h | 5 + .../DynamicTableFactoryDxe.c | 10 + .../SmbiosTableFactory/SmbiosTableFactory.c | 108 +++ .../DynamicTableManagerDxe.c | 677 +++++++++++++++++- .../DynamicTableManagerDxe.inf | 3 +- .../Protocol/DynamicTableFactoryProtocol.h | 10 + .../Include/SmbiosTableGenerator.h | 204 +++++- MdePkg/Include/IndustryStandard/SmBios.h | 8 + 8 files changed, 994 insertions(+), 31 deletions(-) diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFa= ctory.h b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFacto= ry.h index b160dcf8ad..20e438ea70 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.h +++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.h @@ -49,6 +49,11 @@ typedef struct DynamicTableFactoryInfo { CustomDtTableGeneratorList[FixedPcdGet16 ( PcdMaxCustomDTGenerators )]; + + /// An array for holding a map of SMBIOS handles and the CM Object + /// token used to build the SMBIOS record. + SMBIOS_HANDLE_MAP + SmbiosHandleMap[MAX_SMBIOS_HANDLES]; } EDKII_DYNAMIC_TABLE_FACTORY_INFO; =20 /** Return a pointer to the ACPI table generator. diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFa= ctoryDxe.c b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFa= ctoryDxe.c index 6d6d3fa746..577cdb576e 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDx= e.c +++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDx= e.c @@ -1,6 +1,7 @@ /** @file Dynamic Table Factory Dxe =20 + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . Copyright (c) 2017 - 2019, ARM Limited. All rights reserved. =20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -44,6 +45,9 @@ EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL DynamicTableFactory= Protocol =3D { GetDtTableGenerator, RegisterDtTableGenerator, DeregisterDtTableGenerator, + AddSmbiosHandle, + FindSmbiosHandle, + FindSmbiosHandleEx, &TableFactoryInfo }; =20 @@ -65,6 +69,12 @@ DynamicTableFactoryDxeInitialize ( ) { EFI_STATUS Status; + UINTN Idx; + + for (Idx =3D 0; Idx < MAX_SMBIOS_HANDLES; Idx++) { + TableFactoryInfo.SmbiosHandleMap[Idx].SmbiosTblHandle =3D SMBIOS_HANDL= E_PI_RESERVED; + TableFactoryInfo.SmbiosHandleMap[Idx].SmbiosCmToken =3D 0; + } =20 Status =3D gBS->InstallProtocolInterface ( &ImageHandle, diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFac= tory/SmbiosTableFactory.c b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe= /SmbiosTableFactory/SmbiosTableFactory.c index 87795919f8..b928c28a14 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/Sm= biosTableFactory.c +++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/Sm= biosTableFactory.c @@ -1,6 +1,7 @@ /** @file SMBIOS Table Factory =20 + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . Copyright (c) 2017 - 2019, ARM Limited. All rights reserved. =20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -12,6 +13,7 @@ #include #include #include +#include #include =20 // Module specific include files. @@ -24,6 +26,71 @@ =20 extern EDKII_DYNAMIC_TABLE_FACTORY_INFO TableFactoryInfo; =20 +/** Add a new entry to the SMBIOS table Map. + + @param [in] Smbios SMBIOS Protocol pointer. + @param [in] SmbiosHandle SMBIOS Handle to be added, if the value SMBI= OS_HANDLE_PI_RESERVED + is passed then a new SmbiosHandle is assigne= d. + @param [in] CmObjectToken CmObjectToken of the CM_OBJECT used to build= the SMBIOS Table + @param [in] GeneratorId Smbios Table Generator Id. + + @retval EFI_SUCCESS Successfully added/generated the handl= e. + @retval EFI_OUT_OF_RESOURCESNULL Failure to add/generate the handle. +**/ +EFI_STATUS +EFIAPI +AddSmbiosHandle ( + IN EFI_SMBIOS_PROTOCOL *Smbios, + IN SMBIOS_HANDLE *SmbiosHandle, + IN CM_OBJECT_TOKEN CmObjectToken, + IN SMBIOS_TABLE_GENERATOR_ID GeneratorId + ) +{ + EFI_STATUS Status; + UINTN Index; + + Status =3D EFI_OUT_OF_RESOURCES; + + for (Index =3D 0; Index < MAX_SMBIOS_HANDLES; Index++) { + if (TableFactoryInfo.SmbiosHandleMap[Index].SmbiosTblHandle =3D=3D SMB= IOS_HANDLE_PI_RESERVED) { + TableFactoryInfo.SmbiosHandleMap[Index].SmbiosTblHandle =3D *Smbio= sHandle; + TableFactoryInfo.SmbiosHandleMap[Index].SmbiosCmToken =3D CmObje= ctToken; + TableFactoryInfo.SmbiosHandleMap[Index].SmbiosGeneratorId =3D Genera= torId; + Status =3D EFI_SU= CCESS; + break; + } + } + + return Status; +} + +/** Return a pointer to the SMBIOS table Map. + + @param [in] GeneratorId The CmObjectToken to look up an SMBIOS Handle. + + @retval SMBIOS_HANDLE_MAP if the CmObjectToken is found. + @retval NULL if not found. +**/ +SMBIOS_HANDLE_MAP * +EFIAPI +FindSmbiosHandle ( + CM_OBJECT_TOKEN CmObjectToken + ) +{ + UINTN Index; + SMBIOS_HANDLE_MAP *SmbiosHandleMap; + + SmbiosHandleMap =3D NULL; + for (Index =3D 0; Index < MAX_SMBIOS_HANDLES; Index++) { + if (TableFactoryInfo.SmbiosHandleMap[Index].SmbiosCmToken =3D=3D CmObj= ectToken) { + SmbiosHandleMap =3D &TableFactoryInfo.SmbiosHandleMap[Index]; + break; + } + } + + return SmbiosHandleMap; +} + /** Return a pointer to the SMBIOS table generator. =20 @param [in] This Pointer to the Dynamic Table Factory Protocol. @@ -229,3 +296,44 @@ DeregisterSmbiosTableGenerator ( DEBUG ((DEBUG_INFO, "Deregistering %s\n", Generator->Description)); return EFI_SUCCESS; } + +/** Find and return SMBIOS handle based on associated CM object token. + + @param [in] GeneratorId SMBIOS generator ID used to build the SMBIO= S Table. + @param [in] CmObjectToken Token of the CM_OBJECT used to build the SM= BIOS Table. + + @return SMBIOS handle of the table associated with SmbiosGeneratorId an= d + CmObjectToken if found. Otherwise, returns 0xFFFF. +**/ +UINT16 +EFIAPI +FindSmbiosHandleEx ( + IN SMBIOS_TABLE_GENERATOR_ID GeneratorId, + IN CM_OBJECT_TOKEN CmObjToken + ) +{ + SMBIOS_HANDLE_MAP *HandleMap; + + if (CmObjToken =3D=3D CM_NULL_TOKEN) { + return SMBIOS_HANDLE_INVALID; + } + + HandleMap =3D FindSmbiosHandle (CmObjToken); + if (HandleMap =3D=3D NULL) { + return SMBIOS_HANDLE_INVALID; + } + + if (HandleMap->SmbiosGeneratorId !=3D GeneratorId) { + DEBUG (( + DEBUG_ERROR, + "%a: Expect ID %d but get %d\n", + __FUNCTION__, + GeneratorId, + HandleMap->SmbiosGeneratorId + )); + ASSERT (FALSE); + return SMBIOS_HANDLE_INVALID; + } + + return HandleMap->SmbiosTblHandle; +} diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableMa= nagerDxe.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableMa= nagerDxe.c index 1e9b811c40..26aa9b55cf 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDx= e.c +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDx= e.c @@ -8,10 +8,13 @@ **/ =20 #include +#include #include #include #include #include +#include +#include =20 // Module specific include files. #include @@ -22,6 +25,7 @@ #include #include #include +#include =20 /// /// Bit definitions for acceptable ACPI table presence formats. @@ -84,6 +88,18 @@ GET_OBJECT_LIST ( CM_STD_OBJ_ACPI_TABLE_INFO ) =20 +/** This macro expands to a function that retrieves the SMBIOS Table + List from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceStandard, + EStdObjSmbiosTableList, + CM_STD_OBJ_SMBIOS_TABLE_INFO + ) + +STATIC VOID *AcpiTableProtocolRegistration; +STATIC VOID *SmbiosProtocolRegistration; + /** A helper function to build and install a single ACPI table. =20 This is a helper function that invokes the Table generator interface @@ -530,6 +546,490 @@ VerifyMandatoryTablesArePresent ( return Status; } =20 +/** A helper function to build and install an SMBIOS table. + + This is a helper function that invokes the Table generator interface + for building an SMBIOS table. It uses the SmbiosProtocol to install the + table, then frees the resources allocated for generating it. + + @param [in] TableFactoryProtocol Pointer to the Table Factory Protocol + interface. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] SmbiosProtocol Pointer to the SMBIOS protocol. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table Info. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Required object is not found. + @retval EFI_BAD_BUFFER_SIZE Size returned by the Configuration Manager + is less than the Object size for the + requested object. +**/ +STATIC +EFI_STATUS +EFIAPI +BuildAndInstallSingleSmbiosTable ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProto= col, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST SMBIOS_TABLE_GENERATOR *CONST Generator, + IN EFI_SMBIOS_PROTOCOL *SmbiosProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo + ) +{ + EFI_STATUS Status; + EFI_STATUS Status1; + SMBIOS_STRUCTURE *SmbiosTable; + CM_OBJECT_TOKEN CmObjToken; + EFI_SMBIOS_HANDLE TableHandle; + + SmbiosTable =3D NULL; + Status =3D Generator->BuildSmbiosTable ( + Generator, + TableFactoryProtocol, + SmbiosTableInfo, + CfgMgrProtocol, + &SmbiosTable, + &CmObjToken + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to Build Table." \ + " TableGeneratorId =3D 0x%x. Status =3D %r\n", + SmbiosTableInfo->TableGeneratorId, + Status + )); + // Free any allocated resources. + goto exit_handler; + } + + if (SmbiosTable =3D=3D NULL) { + Status =3D EFI_NOT_FOUND; + goto exit_handler; + } + + TableHandle =3D SMBIOS_HANDLE_PI_RESERVED; + // Install SMBIOS table + Status =3D SmbiosProtocol->Add ( + SmbiosProtocol, + NULL, + &TableHandle, + SmbiosTable + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to Install SMBIOS Table. Status =3D %r\n", + Status + )); + // Free any allocated resources. + goto exit_handler; + } + + Status =3D TableFactoryProtocol->AddSmbiosHandle ( + SmbiosProtocol, + &TableHandle, + CmObjToken, + SmbiosTableInfo->TableGeneratorId + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to Add SMBIOS Handle. Status =3D %r\n", + Status + )); + // Free any allocated resources. + goto exit_handler; + } + + DEBUG (( + DEBUG_INFO, + "INFO: SMBIOS Table installed. Status =3D %r\n", + Status + )); + +exit_handler: + // Free any resources allocated for generating the tables. + if (Generator->FreeTableResources !=3D NULL) { + Status1 =3D Generator->FreeTableResources ( + Generator, + TableFactoryProtocol, + SmbiosTableInfo, + CfgMgrProtocol, + &SmbiosTable + ); + if (EFI_ERROR (Status1)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to Free Table Resources." \ + "TableGeneratorId =3D 0x%x. Status =3D %r\n", + SmbiosTableInfo->TableGeneratorId, + Status1 + )); + } + + // Return the first error status in case of failure + if (!EFI_ERROR (Status)) { + Status =3D Status1; + } + } + + return Status; +} + +/** A helper function to build and install multiple SMBIOS tables. + + This is a helper function that invokes the Table generator interface + for building SMBIOS tables. It uses the SmbiosProtocol to install the + tables, then frees the resources allocated for generating it. + + @param [in] TableFactoryProtocol Pointer to the Table Factory Protocol + interface. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] Generator Pointer to the SmbiosTable generator. + @param [in] SmbiosProtocol Pointer to the Smbios protocol. + @param [in] AcpiTableInfo Pointer to the SMBIOS table Info. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Required object is not found. + @retval EFI_BAD_BUFFER_SIZE Size returned by the Configuration Manager + is less than the Object size for the + requested object. +**/ +STATIC +EFI_STATUS +EFIAPI +BuildAndInstallMultipleSmbiosTables ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProto= col, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST SMBIOS_TABLE_GENERATOR *CONST Generator, + IN EFI_SMBIOS_PROTOCOL *SmbiosProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo + ) +{ + EFI_STATUS Status; + EFI_STATUS Status1; + SMBIOS_STRUCTURE **SmbiosTable; + CM_OBJECT_TOKEN *CmObjToken; + EFI_SMBIOS_HANDLE TableHandle; + UINTN TableCount; + UINTN Index; + + TableCount =3D 0; + Status =3D Generator->BuildSmbiosTableEx ( + Generator, + TableFactoryProtocol, + SmbiosTableInfo, + CfgMgrProtocol, + &SmbiosTable, + &CmObjToken, + &TableCount + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to Build Table." \ + " TableGeneratorId =3D 0x%x. Status =3D %r\n", + SmbiosTableInfo->TableGeneratorId, + Status + )); + // Free any allocated resources. + goto exit_handler; + } + + if ((SmbiosTable =3D=3D NULL) || (TableCount =3D=3D 0)) { + Status =3D EFI_NOT_FOUND; + DEBUG (( + DEBUG_ERROR, + "%a: TableCount %u SmbiosTable %p \n", + __FUNCTION__, + TableCount, + SmbiosTable + )); + goto exit_handler; + } + + for (Index =3D 0; Index < TableCount; Index++) { + TableHandle =3D SMBIOS_HANDLE_PI_RESERVED; + + // Install SMBIOS table + Status =3D SmbiosProtocol->Add ( + SmbiosProtocol, + NULL, + &TableHandle, + SmbiosTable[Index] + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to Install SMBIOS Table. Status =3D %r\n", + Status + )); + // Free any allocated resources. + goto exit_handler; + } + + Status =3D TableFactoryProtocol->AddSmbiosHandle ( + SmbiosProtocol, + &TableHandle, + CmObjToken[Index], + SmbiosTableInfo->TableGeneratorId + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to Add SMBIOS Handle. Status =3D %r\n", + Status + )); + // Free any allocated resources. + goto exit_handler; + } + + DEBUG (( + DEBUG_INFO, + "INFO: SMBIOS Table installed. Status =3D %r\n", + Status + )); + } + +exit_handler: + // Free any resources allocated for generating the tables. + if (Generator->FreeTableResourcesEx !=3D NULL) { + Status1 =3D Generator->FreeTableResourcesEx ( + Generator, + TableFactoryProtocol, + SmbiosTableInfo, + CfgMgrProtocol, + &SmbiosTable, + &CmObjToken, + TableCount + ); + if (EFI_ERROR (Status1)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to Free Table Resources." \ + "TableGeneratorId =3D 0x%x. Status =3D %r\n", + SmbiosTableInfo->TableGeneratorId, + Status1 + )); + } + + // Return the first error status in case of failure + if (!EFI_ERROR (Status)) { + Status =3D Status1; + } + } + + DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status)); + return Status; +} + +/** A helper function to invoke a Table generator + + This is a helper function that invokes the Table generator interface + for building an SMBIOS table. It uses the SmbiosProtocol to install the + table, then frees the resources allocated for generating it. + + @param [in] TableFactoryProtocol Pointer to the Table Factory Protocol + interface. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] SmbiosProtocol Pointer to the SMBIOS protocol. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table Info. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Required object is not found. + @retval EFI_BAD_BUFFER_SIZE Size returned by the Configuration Manager + is less than the Object size for the + requested object. +**/ +EFI_STATUS +EFIAPI +BuildAndInstallSmbiosTable ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProto= col, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN EFI_SMBIOS_PROTOCOL *SmbiosProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo + ) +{ + EFI_STATUS Status; + CONST SMBIOS_TABLE_GENERATOR *Generator; + + ASSERT (TableFactoryProtocol !=3D NULL); + ASSERT (CfgMgrProtocol !=3D NULL); + ASSERT (SmbiosProtocol !=3D NULL); + ASSERT (SmbiosTableInfo !=3D NULL); + + DEBUG (( + DEBUG_INFO, + "INFO: EStdObjSmbiosTableList: Address =3D 0x%p," \ + " TableGeneratorId =3D 0x%x\n", + SmbiosTableInfo, + SmbiosTableInfo->TableGeneratorId + )); + + Generator =3D NULL; + Status =3D TableFactoryProtocol->GetSmbiosTableGenerator ( + TableFactoryProtocol, + SmbiosTableInfo->TableGeneratorId, + &Generator + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Table Generator not found." \ + " TableGeneratorId =3D 0x%x. Status =3D %r\n", + SmbiosTableInfo->TableGeneratorId, + Status + )); + return Status; + } + + if (Generator =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + DEBUG (( + DEBUG_INFO, + "INFO: Generator found : %s\n", + Generator->Description + )); + + if (Generator->BuildSmbiosTableEx !=3D NULL) { + Status =3D BuildAndInstallMultipleSmbiosTables ( + TableFactoryProtocol, + CfgMgrProtocol, + Generator, + SmbiosProtocol, + SmbiosTableInfo + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to find build and install SMBIOS Tables." \ + " Status =3D %r\n", + Status + )); + } + } else if (Generator->BuildSmbiosTable !=3D NULL) { + Status =3D BuildAndInstallSingleSmbiosTable ( + TableFactoryProtocol, + CfgMgrProtocol, + Generator, + SmbiosProtocol, + SmbiosTableInfo + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to find build and install SMBIOS Table." \ + " Status =3D %r\n", + Status + )); + } + } else { + Status =3D EFI_INVALID_PARAMETER; + DEBUG (( + DEBUG_ERROR, + "ERROR: Table Generator does not implement the" \ + "SMBIOS_TABLE_GENERATOR_BUILD_TABLE interface." \ + " TableGeneratorId =3D 0x%x. Status =3D %r\n", + SmbiosTableInfo->TableGeneratorId, + Status + )); + } + + DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status)); + return Status; +} + +/** Generate and install SMBIOS tables. + + The function gathers the information necessary for installing the + SMBIOS tables from the Configuration Manager, invokes the generators + and installs them (via BuildAndInstallAcpiTable). + + @param [in] TableFactoryProtocol Pointer to the Table Factory Protocol + interface. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + + @retval EFI_SUCCESS Success. + @retval EFI_NOT_FOUND If a mandatory table or a generator is not found. +**/ +STATIC +EFI_STATUS +EFIAPI +ProcessSmbiosTables ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProto= col, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol + ) +{ + EFI_STATUS Status; + EFI_SMBIOS_PROTOCOL *SmbiosProtocol; + CM_STD_OBJ_SMBIOS_TABLE_INFO *SmbiosTableInfo; + UINT32 SmbiosTableCount; + + Status =3D gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)= &SmbiosProtocol); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Could not locate SMBIOS protocol. %r\n", Status= )); + return Status; + } + + Status =3D GetEStdObjSmbiosTableList ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &SmbiosTableInfo, + &SmbiosTableCount + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to get SMBIOS Table List. Status =3D %r\n", + Status + )); + return Status; + } + + if (SmbiosTableCount =3D=3D 0) { + DEBUG (( + DEBUG_ERROR, + "ERROR: EStdObjSmbiosTableList: SmbiosTableCount =3D %d\n", + SmbiosTableCount + )); + return EFI_NOT_FOUND; + } + + DEBUG (( + DEBUG_INFO, + "INFO: EStdObjSmbiosTableList: SmbiosTableCount =3D %d\n", + SmbiosTableCount + )); + + InitSmbiosTableDispatcher (SmbiosTableInfo, SmbiosTableCount); + + Status =3D DispatchSmbiosTables ( + TableFactoryProtocol, + CfgMgrProtocol, + SmbiosProtocol, + SmbiosTableInfo, + SmbiosTableCount + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to install SMBIOS Tables.Status =3D %r\n", + Status + )); + } + + return Status; +} + /** Generate and install ACPI tables. =20 The function gathers the information necessary for installing the @@ -701,30 +1201,20 @@ ProcessAcpiTables ( return Status; } =20 -/** Entrypoint of Dynamic Table Manager Dxe. +/** Callback function for ACPI Protocol . =20 - The Dynamic Table Manager uses the Configuration Manager Protocol - to get the list of ACPI and SMBIOS tables to install. For each table - in the list it requests the corresponding ACPI/SMBIOS table factory for - a generator capable of building the ACPI/SMBIOS table. - If a suitable table generator is found, it invokes the generator interfa= ce - to build the table. The Dynamic Table Manager then installs the - table and invokes another generator interface to free any resources - allocated for building the table. + Callback function for ACPI protocol that installs ACPI tables =20 - @param ImageHandle - @param SystemTable + @param Event + @param Context =20 - @retval EFI_SUCCESS Success. - @retval EFI_OUT_OF_RESOURCES Memory allocation failed. - @retval EFI_NOT_FOUND Required interface/object was not found. - @retval EFI_INVALID_PARAMETER Some parameter is incorrect/invalid. + @retval None **/ -EFI_STATUS -EFIAPI -DynamicTableManagerDxeInitialize ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +STATIC +VOID +AcpiTableProtocolReady ( + IN EFI_EVENT Event, + IN VOID *Context ) { EFI_STATUS Status; @@ -745,7 +1235,7 @@ DynamicTableManagerDxeInitialize ( " Status =3D %r\n", Status )); - return Status; + return; } =20 // Locate the Configuration Manager for the Platform @@ -760,7 +1250,7 @@ DynamicTableManagerDxeInitialize ( "ERROR: Failed to find Configuration Manager protocol. Status =3D %r= \n", Status )); - return Status; + return; } =20 Status =3D GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo); @@ -770,7 +1260,7 @@ DynamicTableManagerDxeInitialize ( "ERROR: Failed to get Configuration Manager info. Status =3D %r\n", Status )); - return Status; + return; } =20 DEBUG (( @@ -793,6 +1283,147 @@ DynamicTableManagerDxeInitialize ( Status )); } +} + +/** Callback function for SMBIOS Protocol . + + Callback function for SMBIOS protocol that installs SMBIOS tables + that use the DynamicTables Package. + + @param Event + @param Context + + @retval None +**/ +STATIC +VOID +SmbiosProtocolReady ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + EDKII_CONFIGURATION_MANAGER_PROTOCOL *CfgMgrProtocol; + CM_STD_OBJ_CONFIGURATION_MANAGER_INFO *CfgMfrInfo; + EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *TableFactoryProtocol; + + // Locate the Dynamic Table Factory + Status =3D gBS->LocateProtocol ( + &gEdkiiDynamicTableFactoryProtocolGuid, + NULL, + (VOID **)&TableFactoryProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to find Dynamic Table Factory protocol." \ + " Status =3D %r\n", + Status + )); + return; + } + + // Locate the Configuration Manager for the Platform + Status =3D gBS->LocateProtocol ( + &gEdkiiConfigurationManagerProtocolGuid, + NULL, + (VOID **)&CfgMgrProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to find Configuration Manager protocol. Status =3D %r= \n", + Status + )); + return; + } + + Status =3D GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to get Configuration Manager info. Status =3D %r\n", + Status + )); + return; + } + + DEBUG (( + DEBUG_INFO, + "INFO: Configuration Manager Version =3D 0x%x, OemID =3D %c%c%c%c%c%c\= n", + CfgMfrInfo->Revision, + CfgMfrInfo->OemId[0], + CfgMfrInfo->OemId[1], + CfgMfrInfo->OemId[2], + CfgMfrInfo->OemId[3], + CfgMfrInfo->OemId[4], + CfgMfrInfo->OemId[5] + )); + + Status =3D ProcessSmbiosTables (TableFactoryProtocol, CfgMgrProtocol); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: SMBIOS Table processing failure. Status =3D %r\n", + Status + )); + } +} + +/** Entrypoint of Dynamic Table Manager Dxe. + + The Dynamic Table Manager uses the Configuration Manager Protocol + to get the list of ACPI and SMBIOS tables to install. For each table + in the list it requests the corresponding ACPI/SMBIOS table factory for + a generator capable of building the ACPI/SMBIOS table. + If a suitable table generator is found, it invokes the generator interfa= ce + to build the table. The Dynamic Table Manager then installs the + table and invokes another generator interface to free any resources + allocated for building the table. + + @param ImageHandle + @param SystemTable + + @retval EFI_SUCCESS Success. + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + @retval EFI_NOT_FOUND Required interface/object was not found. + @retval EFI_INVALID_PARAMETER Some parameter is incorrect/invalid. +**/ +EFI_STATUS +EFIAPI +DynamicTableManagerDxeInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT AcpiEvent; + EFI_EVENT SmbiosEvent; + + AcpiEvent =3D EfiCreateProtocolNotifyEvent ( + &gEfiAcpiTableProtocolGuid, + TPL_CALLBACK, + AcpiTableProtocolReady, + NULL, + &AcpiTableProtocolRegistration + ); + if (AcpiEvent =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Failed to ACPI create protocol event\r\n", _= _FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + + SmbiosEvent =3D EfiCreateProtocolNotifyEvent ( + &gEfiSmbiosProtocolGuid, + TPL_CALLBACK, + SmbiosProtocolReady, + NULL, + &SmbiosProtocolRegistration + ); + if (SmbiosEvent =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Failed to SMBIOS create protocol event\r\n",= __FUNCTION__)); + gBS->CloseEvent (AcpiEvent); + return EFI_OUT_OF_RESOURCES; + } =20 return Status; } diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableMa= nagerDxe.inf b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTable= ManagerDxe.inf index b09272d883..3beab7420a 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDx= e.inf +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDx= e.inf @@ -33,6 +33,7 @@ [LibraryClasses] PrintLib TableHelperLib + UefiLib UefiBootServicesTableLib UefiDriverEntryPoint =20 @@ -42,12 +43,12 @@ [Protocols] gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiAcpiSdtProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiSmbiosProtocolGuid # PROTOCOL ALWAYS_CONSUMED =20 gEdkiiConfigurationManagerProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEdkiiDynamicTableFactoryProtocolGuid # PROTOCOL ALWAYS_CONSUMED =20 [Depex] - gEfiAcpiTableProtocolGuid AND gEdkiiConfigurationManagerProtocolGuid AND gEdkiiDynamicTableFactoryProtocolGuid =20 diff --git a/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.= h b/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h index b11fc0c9f1..e298236311 100644 --- a/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h +++ b/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h @@ -1,5 +1,6 @@ /** @file =20 + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . Copyright (c) 2017 - 2019, ARM Limited. All rights reserved. =20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -239,6 +240,15 @@ typedef struct DynamicTableFactoryProtocol { EDKII_DYNAMIC_TABLE_FACTORY_DEREGISTER_DT_TABLE_GENERATOR DeregisterDtTa= bleGenerator; =20 + EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_ADD_HANDLE + AddSmbiosHandl= e; + + EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_GET_HANDLE + GetSmbiosHandl= e; + + EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_GET_HANDLE_EX + GetSmbiosHandl= eEx; + /** Pointer to the data structure that holds the list of registered table generators */ diff --git a/DynamicTablesPkg/Include/SmbiosTableGenerator.h b/DynamicTable= sPkg/Include/SmbiosTableGenerator.h index 934d56c90d..a9f8199a3b 100644 --- a/DynamicTablesPkg/Include/SmbiosTableGenerator.h +++ b/DynamicTablesPkg/Include/SmbiosTableGenerator.h @@ -1,5 +1,6 @@ /** @file =20 + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . Copyright (c) 2017 - 2019, ARM Limited. All rights reserved. =20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -10,7 +11,7 @@ #define SMBIOS_TABLE_GENERATOR_H_ =20 #include - +#include #include =20 #pragma pack(1) @@ -121,12 +122,21 @@ typedef enum StdSmbiosTableGeneratorId { ETableGeneratorNameSpaceStd, \ TableId \ ) +#define MAX_SMBIOS_HANDLES (255) =20 /** Forward declarations. */ typedef struct ConfigurationManagerProtocol EDKII_CONFIGURATION_MANAGER_PR= OTOCOL; typedef struct CmStdObjSmbiosTableInfo CM_STD_OBJ_SMBIOS_TABLE_INFO; typedef struct SmbiosTableGenerator SMBIOS_TABLE_GENERATOR; +typedef struct DynamicTableFactoryProtocol EDKII_DYNAMIC_TABLE_FACTORY_PR= OTOCOL; +typedef UINTN CM_OBJECT_TOKEN; + +typedef struct SmbiosHandleCmObjMap { + SMBIOS_TABLE_GENERATOR_ID SmbiosGeneratorId; + SMBIOS_HANDLE SmbiosTblHandle; + CM_OBJECT_TOKEN SmbiosCmToken; +} SMBIOS_HANDLE_MAP; =20 /** This function pointer describes the interface to SMBIOS table build functions provided by the SMBIOS table generator and called by the @@ -143,9 +153,11 @@ typedef struct SmbiosTableGenerator SMBIOS_TAB= LE_GENERATOR; **/ typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_BUILD_TABLE) ( IN CONST SMBIOS_TABLE_GENERATOR *Generator, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProt= ocol, IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, - OUT SMBIOS_STRUCTURE **Table + OUT SMBIOS_STRUCTURE **Table, + OUT CM_OBJECT_TOKEN *CmObjToken ); =20 /** This function pointer describes the interface to used by the @@ -163,32 +175,147 @@ typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_BUILD_TA= BLE) ( **/ typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_FREE_TABLE) ( IN CONST SMBIOS_TABLE_GENERATOR *Generator, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProt= ocol, IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, IN SMBIOS_STRUCTURE **Table ); =20 +/** This function pointer describes the interface to SMBIOS table build + functions provided by the SMBIOS table generator and called by the + Table Manager to build an SMBIOS table. + + @param [in] Generator Pointer to the SMBIOS table generator. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to the generated SMBIOS table. + + @return EFI_SUCCESS If the table is generated successfully or other + failure codes as returned by the generator. +**/ +typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_BUILD_TABLEEX) ( + IN CONST SMBIOS_TABLE_GENERATOR *Generator, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryPro= tocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo= , + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE ***Table, + OUT CM_OBJECT_TOKEN **CmObjectToken= , + OUT UINTN *CONST TableCount + ); + +/** This function pointer describes the interface to used by the + Table Manager to give the generator an opportunity to free + any resources allocated for building the SMBIOS table. + + @param [in] Generator Pointer to the SMBIOS table generator. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] Table Pointer to the generated SMBIOS table. + + @return EFI_SUCCESS If freed successfully or other failure codes + as returned by the generator. +**/ +typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_FREE_TABLEEX) ( + IN CONST SMBIOS_TABLE_GENERATOR *Generator, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProt= ocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE ***Table, + IN CM_OBJECT_TOKEN **CmObjectToken, + IN CONST UINTN TableCount + ); + +/** This function pointer describes the interface to used by the + Table Manager to give the generator an opportunity to add + an SMBIOS Handle. + + This function is called by the Dynamic Table Manager to add a newly adde= d + SMBIOS Table OR it can be called by an SMBIOS Table generator to create + and add a new SMBIOS Handle if there is a reference to another table and + if there is a generator for that table that hasn't been called yet. + + @param [in] Smbios Pointer to the SMBIOS protocol. + @param [in] SmbiosHandle Pointer to an SMBIOS handle (either generate= d by + SmbiosDxe Driver or SMBIOS_HANDLE_PI_RESERV= ED + if a handle needs to be generated). + @param [in] CmObjectToken The CM Object token for that is used to gene= rate + SMBIOS record. + @param [in] GeneratorId The SMBIOS table generator Id. + + @retval EFI_SUCCESS Success. + @retval EFI_OUT_OF_RESOURCES Unable to add the handle. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +typedef EFI_STATUS (EFIAPI *EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_ADD_H= ANDLE)( + IN EFI_SMBIOS_PROTOCOL *Smbios, + IN SMBIOS_HANDLE *SmbiosHandle, + IN CM_OBJECT_TOKEN CmObjectToken, + IN SMBIOS_TABLE_GENERATOR_ID GeneratorId + ); + +/** This function pointer describes the interface to used by the + Table Manager to give the generator an opportunity to find + an SMBIOS Handle. + + This function is called by the SMBIOS table generator to find an SMBIOS + handle needed as part of generating an SMBIOS Table. + + @param [in] CmObjectToken The CM Object token used to generate the S= MBIOS + record. + + @retval EFI_SUCCESS Success. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +typedef SMBIOS_HANDLE_MAP *(EFIAPI *EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TAB= LE_GET_HANDLE)( + IN CM_OBJECT_TOKEN CmObjectToken + ); + +/** Find and return SMBIOS handle based on associated CM object token. + + @param [in] GeneratorId SMBIOS generator ID used to build the SMBIO= S Table. + @param [in] CmObjectToken Token of the CM_OBJECT used to build the SM= BIOS Table. + + @return SMBIOS handle of the table associated with SmbiosTableId and + CmObjectToken if found. Otherwise, returns 0xFFFF. +**/ +typedef UINT16 (EFIAPI *EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_GET_HANDL= E_EX)( + IN SMBIOS_TABLE_GENERATOR_ID GeneratorId, + IN CM_OBJECT_TOKEN CmObjToken + ); + /** The SMBIOS_TABLE_GENERATOR structure provides an interface that the Table Manager can use to invoke the functions to build SMBIOS tables. */ typedef struct SmbiosTableGenerator { /// The SMBIOS table generator ID. - SMBIOS_TABLE_GENERATOR_ID GeneratorID; + SMBIOS_TABLE_GENERATOR_ID GeneratorID; =20 /// String describing the DT table /// generator. - CONST CHAR16 *Description; + CONST CHAR16 *Description; =20 /// The SMBIOS table type. - SMBIOS_TYPE Type; + SMBIOS_TYPE Type; =20 /// SMBIOS table build function pointer. - SMBIOS_TABLE_GENERATOR_BUILD_TABLE BuildSmbiosTable; + SMBIOS_TABLE_GENERATOR_BUILD_TABLE BuildSmbiosTable; + + /** The function to free any resources + allocated for building the SMBIOS table. + */ + SMBIOS_TABLE_GENERATOR_FREE_TABLE FreeTableResources; + + /// SMBIOS table extended build function pointer. + SMBIOS_TABLE_GENERATOR_BUILD_TABLEEX BuildSmbiosTableEx; =20 /** The function to free any resources allocated for building the SMBIOS table. */ - SMBIOS_TABLE_GENERATOR_FREE_TABLE FreeTableResources; + SMBIOS_TABLE_GENERATOR_FREE_TABLEEX FreeTableResourcesEx; } SMBIOS_TABLE_GENERATOR; =20 /** Register SMBIOS table factory generator. @@ -229,6 +356,69 @@ DeregisterSmbiosTableGenerator ( IN CONST SMBIOS_TABLE_GENERATOR *CONST Generator ); =20 +/** Add SMBIOS Handle. + + This function is called by the Dynamic Table Manager to add a newly adde= d + SMBIOS Table OR it can be called by an SMBIOS Table generator to create + and add a new SMBIOS Handle if there is a reference to another table and + if there is a generator for that table that hasn't been called yet. + + @param [in] Smbios Pointer to the SMBIOS protocol. + @param [in] SmbiosHandle Pointer to an SMBIOS handle (either generate= d by + SmbiosDxe Driver or SMBIOS_HANDLE_PI_RESERV= ED + if a handle needs to be generated). + @param [in] CmObjectToken The CM Object token for that is used to gene= rate + SMBIOS record. + @param [in] GeneratorId The SMBIOS table generator Id. + + @retval EFI_SUCCESS Success. + @retval EFI_OUT_OF_RESOURCES Unable to add the handle. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +EFI_STATUS +EFIAPI +AddSmbiosHandle ( + IN EFI_SMBIOS_PROTOCOL *Smbios, + IN SMBIOS_HANDLE *SmbiosHandle, + IN CM_OBJECT_TOKEN CmObjectToken, + IN SMBIOS_TABLE_GENERATOR_ID GeneratorId + ); + +/** Find SMBIOS Handle given the CM Object token used to generate the SMBI= OS + record.. + + This function is called by the SMBIOS table generator to find an SMBIOS + handle needed as part of generating an SMBIOS Table. + + @param [in] CmObjectToken The CM Object token used to generate the S= MBIOS + record. + + @retval EFI_SUCCESS Success. + @retval EFI_NOT_FOUND The requested generator is not found + in the list of registered generators. +**/ +SMBIOS_HANDLE_MAP * +EFIAPI +FindSmbiosHandle ( + IN CM_OBJECT_TOKEN CmObjectToken + ); + +/** Find and return SMBIOS handle based on associated CM object token. + + @param [in] GeneratorId SMBIOS generator ID used to build the SMBIO= S Table. + @param [in] CmObjectToken Token of the CM_OBJECT used to build the SM= BIOS Table. + + @return SMBIOS handle of the table associated with SmbiosTableId and + CmObjectToken if found. Otherwise, returns 0xFFFF. +**/ +UINT16 +EFIAPI +FindSmbiosHandleEx ( + IN SMBIOS_TABLE_GENERATOR_ID GeneratorId, + IN CM_OBJECT_TOKEN CmObjToken + ); + #pragma pack() =20 #endif // SMBIOS_TABLE_GENERATOR_H_ diff --git a/MdePkg/Include/IndustryStandard/SmBios.h b/MdePkg/Include/Indu= stryStandard/SmBios.h index 89985bb418..c40986157c 100644 --- a/MdePkg/Include/IndustryStandard/SmBios.h +++ b/MdePkg/Include/IndustryStandard/SmBios.h @@ -28,6 +28,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent /// #define SMBIOS_HANDLE_PI_RESERVED 0xFFFE =20 +/// +/// Reference SMBIOS 3.6, chapter 6.1.2. +/// Unless otherwise specified, when referring to another structure=E2=80= =99s handle, the value +/// 0FFFFh is used to indicate that the referenced handle is not applicabl= e or does not +/// exist. +/// +#define SMBIOS_HANDLE_INVALID 0xFFFF + /// /// Reference SMBIOS 2.6, chapter 3.1.3. /// Each text string is limited to 64 significant characters due to system= MIF limitations. --=20 2.17.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 (#107255): https://edk2.groups.io/g/devel/message/107255 Mute This Topic: https://groups.io/mt/100361559/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-