Skip to content

Commit 6e3d031

Browse files
DynamicTablesPkg: Smbios Bios Information (Type 0)
Generator for Smbios Bios Information table (Type 0). Co-authored-by: Thejaswani Putta <tputta@nvidia.com> Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com>
1 parent 0dddd65 commit 6e3d031

4 files changed

Lines changed: 372 additions & 0 deletions

File tree

DynamicTablesPkg/DynamicTables.dsc.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107

108108
DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Lib.inf
109109
DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Lib.inf
110+
DynamicTablesPkg/Library/Smbios/SmbiosType0Lib/SmbiosType0Lib.inf
110111

111112
# AML Fixup (Arm specific)
112113
DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtCmn600LibArm/SsdtCmn600LibArm.inf
@@ -151,6 +152,7 @@
151152

152153
NULL|DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Lib.inf
153154
NULL|DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Lib.inf
155+
NULL|DynamicTablesPkg/Library/Smbios/SmbiosType0Lib/SmbiosType0Lib.inf
154156
}
155157

156158
[Components.RISCV64]

DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ typedef enum ArchCommonObjectID {
7373
EArchCommonObjTpm2DeviceInfo, ///< 46 - TPM2 Device Info
7474
EArchCommonObjMcfgPciConfigSpaceInfo, ///< 47 - MCFG PCI Configuration Space Info
7575
EArchCommonObjPciRootPortInfo, ///< 48 - PCI root port configuration Info
76+
EArchCommonObjBiosInfo = 52, ///< 52 - BIOS Info
7677
EArchCommonObjMax
7778
} EARCH_COMMON_OBJECT_ID;
7879

@@ -1132,4 +1133,39 @@ typedef struct CmArchCommonObjSpcrInfo {
11321133
UINT8 TerminalType;
11331134
} CM_ARCH_COMMON_SPCR_INFO;
11341135

1136+
/** A structure that describes BIOS Information.
1137+
1138+
SMBIOS Specification v3.6.0 Type 0
1139+
1140+
ID: EArchCommonObjBiosInfo
1141+
**/
1142+
typedef struct CmArchCommonBiosInfo {
1143+
/// BIOS vendor name string.
1144+
CHAR8 *BiosVendor;
1145+
/// BIOS version string.
1146+
CHAR8 *BiosVersion;
1147+
/// BIOS starting address segment.
1148+
UINT16 BiosSegment;
1149+
/// BIOS release date string.
1150+
CHAR8 *BiosReleaseDate;
1151+
/// BIOS ROM size (in 64 KB blocks minus one).
1152+
UINT8 BiosSize;
1153+
/// Bit field of supported BIOS functions.
1154+
MISC_BIOS_CHARACTERISTICS BiosCharacteristics;
1155+
/// Optional set of functions that BIOS supports (bytes 0 and 1).
1156+
UINT8 BIOSCharacteristicsExtensionBytes[2];
1157+
/// System BIOS firmware major version.
1158+
UINT8 SystemBiosMajorRelease;
1159+
/// System BIOS firmware minor version.
1160+
UINT8 SystemBiosMinorRelease;
1161+
/// Embedded Controller firmware major release.
1162+
UINT8 ECFirmwareMajorRelease;
1163+
/// Embedded Controller firmware minor release.
1164+
UINT8 ECFirmwareMinorRelease;
1165+
/// Extended BIOS ROM size.
1166+
EXTENDED_BIOS_ROM_SIZE ExtendedBiosSize;
1167+
/// CM Object Token uniquely identifying this BIOS info entry.
1168+
CM_OBJECT_TOKEN BiosInfoToken;
1169+
} CM_ARCH_COMMON_BIOS_INFO;
1170+
11351171
#pragma pack()
Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
/** @file
2+
SMBIOS Type0 Table Generator.
3+
4+
Copyright (c) 2024 - 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5+
Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR>
6+
7+
SPDX-License-Identifier: BSD-2-Clause-Patent
8+
**/
9+
10+
#include <Library/BaseLib.h>
11+
#include <Library/BaseMemoryLib.h>
12+
#include <Library/DebugLib.h>
13+
#include <Library/MemoryAllocationLib.h>
14+
#include <Library/SmbiosStringTableLib.h>
15+
16+
// Module specific include files.
17+
#include <ConfigurationManagerObject.h>
18+
#include <ConfigurationManagerHelper.h>
19+
#include <Protocol/ConfigurationManagerProtocol.h>
20+
#include <Protocol/DynamicTableFactoryProtocol.h>
21+
#include <Protocol/Smbios.h>
22+
#include <IndustryStandard/SmBios.h>
23+
24+
/** This macro expands to a function that retrieves the BIOS Information
25+
from the Configuration Manager.
26+
*/
27+
GET_OBJECT_LIST (
28+
EObjNameSpaceArchCommon,
29+
EArchCommonObjBiosInfo,
30+
CM_ARCH_COMMON_BIOS_INFO
31+
)
32+
33+
/**
34+
Free any resources allocated when installing SMBIOS Type0 table.
35+
36+
@param [in] This Pointer to the SMBIOS table generator.
37+
@param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory
38+
Protocol interface.
39+
@param [in] SmbiosTableInfo Pointer to the SMBIOS table information.
40+
@param [in] CfgMgrProtocol Pointer to the Configuration Manager
41+
Protocol interface.
42+
@param [in] Table Pointer to the SMBIOS table.
43+
44+
@retval EFI_SUCCESS Table freed successfully.
45+
**/
46+
STATIC
47+
EFI_STATUS
48+
FreeSmbiosType0Table (
49+
IN CONST SMBIOS_TABLE_GENERATOR *CONST This,
50+
IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol,
51+
IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo,
52+
IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol,
53+
IN SMBIOS_STRUCTURE **CONST Table
54+
)
55+
{
56+
if (*Table != NULL) {
57+
FreePool (*Table);
58+
}
59+
60+
return EFI_SUCCESS;
61+
}
62+
63+
/** Construct SMBIOS Type0 Table describing BIOS information.
64+
65+
If this function allocates any resources then they must be freed
66+
in the FreeSmbiosType0Table function.
67+
68+
@param [in] This Pointer to the SMBIOS table generator.
69+
@param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory
70+
Protocol interface.
71+
@param [in] SmbiosTableInfo Pointer to the SMBIOS table information.
72+
@param [in] CfgMgrProtocol Pointer to the Configuration Manager
73+
Protocol interface.
74+
@param [out] Table Pointer to the SMBIOS table.
75+
@param [out] CmObjectToken Pointer to the CM Object Token.
76+
77+
@retval EFI_SUCCESS Table generated successfully.
78+
@retval EFI_INVALID_PARAMETER A parameter is invalid.
79+
@retval EFI_NOT_FOUND Could not find information.
80+
@retval EFI_OUT_OF_RESOURCES Could not allocate memory.
81+
**/
82+
STATIC
83+
EFI_STATUS
84+
BuildSmbiosType0Table (
85+
IN CONST SMBIOS_TABLE_GENERATOR *This,
86+
IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol,
87+
IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo,
88+
IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol,
89+
OUT SMBIOS_STRUCTURE **Table,
90+
OUT CM_OBJECT_TOKEN *CmObjectToken
91+
)
92+
{
93+
EFI_STATUS Status;
94+
CM_OBJECT_TOKEN CmObject;
95+
UINT8 VendorRef;
96+
UINT8 VersionRef;
97+
UINT8 ReleaseDateRef;
98+
SMBIOS_TABLE_TYPE0 *SmbiosRecord;
99+
UINTN SmbiosRecordSize;
100+
STRING_TABLE StrTable;
101+
CHAR8 *OptionalStrings;
102+
CM_ARCH_COMMON_BIOS_INFO *BiosInfo;
103+
104+
ASSERT (This != NULL);
105+
ASSERT (SmbiosTableInfo != NULL);
106+
ASSERT (CfgMgrProtocol != NULL);
107+
ASSERT (Table != NULL);
108+
ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID);
109+
110+
//
111+
// Retrieve BIOS info from CM object
112+
//
113+
*Table = NULL;
114+
Status = GetEArchCommonObjBiosInfo (
115+
CfgMgrProtocol,
116+
CM_NULL_TOKEN,
117+
&BiosInfo,
118+
NULL
119+
);
120+
if (EFI_ERROR (Status)) {
121+
DEBUG ((
122+
DEBUG_ERROR,
123+
"%a: Failed to get Bios Info CM Object %r\n",
124+
__func__,
125+
Status
126+
));
127+
return Status;
128+
}
129+
130+
//
131+
// Copy strings to SMBIOS table
132+
//
133+
Status = StringTableInitialize (&StrTable, 3);
134+
if (EFI_ERROR (Status)) {
135+
DEBUG ((
136+
DEBUG_ERROR,
137+
"%a: Failed to allocate string table for CM Object, %r\n",
138+
__func__,
139+
Status
140+
));
141+
goto exit;
142+
}
143+
144+
VendorRef = 0;
145+
VersionRef = 0;
146+
ReleaseDateRef = 0;
147+
148+
if ((BiosInfo->BiosVendor != NULL) && (BiosInfo->BiosVendor[0] != '\0')) {
149+
Status = StringTableAddString (&StrTable, BiosInfo->BiosVendor, &VendorRef);
150+
if (EFI_ERROR (Status)) {
151+
DEBUG ((DEBUG_ERROR, "%a: Failed to add BiosVendor string %r\n", __func__, Status));
152+
goto exit;
153+
}
154+
}
155+
156+
if ((BiosInfo->BiosVersion != NULL) && (BiosInfo->BiosVersion[0] != '\0')) {
157+
Status = StringTableAddString (&StrTable, BiosInfo->BiosVersion, &VersionRef);
158+
if (EFI_ERROR (Status)) {
159+
DEBUG ((DEBUG_ERROR, "%a: Failed to add BiosVersion string %r\n", __func__, Status));
160+
goto exit;
161+
}
162+
}
163+
164+
if ((BiosInfo->BiosReleaseDate != NULL) && (BiosInfo->BiosReleaseDate[0] != '\0')) {
165+
Status = StringTableAddString (&StrTable, BiosInfo->BiosReleaseDate, &ReleaseDateRef);
166+
if (EFI_ERROR (Status)) {
167+
DEBUG ((DEBUG_ERROR, "%a: Failed to add BiosReleaseDate string %r\n", __func__, Status));
168+
goto exit;
169+
}
170+
}
171+
172+
SmbiosRecordSize = sizeof (SMBIOS_TABLE_TYPE0) +
173+
StringTableGetStringSetSize (&StrTable);
174+
SmbiosRecord = (SMBIOS_TABLE_TYPE0 *)AllocateZeroPool (SmbiosRecordSize);
175+
if (SmbiosRecord == NULL) {
176+
DEBUG ((DEBUG_ERROR, "%a: memory allocation failed for smbios type0 record\n", __func__));
177+
Status = EFI_OUT_OF_RESOURCES;
178+
goto exit;
179+
}
180+
181+
SmbiosRecord->BiosSegment = BiosInfo->BiosSegment;
182+
SmbiosRecord->BiosSize = BiosInfo->BiosSize;
183+
184+
SmbiosRecord->BiosCharacteristics = BiosInfo->BiosCharacteristics;
185+
186+
SmbiosRecord->BIOSCharacteristicsExtensionBytes[0] = BiosInfo->BIOSCharacteristicsExtensionBytes[0];
187+
SmbiosRecord->BIOSCharacteristicsExtensionBytes[1] = BiosInfo->BIOSCharacteristicsExtensionBytes[1];
188+
189+
SmbiosRecord->SystemBiosMajorRelease = BiosInfo->SystemBiosMajorRelease;
190+
SmbiosRecord->SystemBiosMinorRelease = BiosInfo->SystemBiosMinorRelease;
191+
192+
SmbiosRecord->EmbeddedControllerFirmwareMajorRelease = BiosInfo->ECFirmwareMajorRelease;
193+
SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = BiosInfo->ECFirmwareMinorRelease;
194+
195+
SmbiosRecord->ExtendedBiosSize = BiosInfo->ExtendedBiosSize;
196+
197+
SmbiosRecord->Vendor = VendorRef;
198+
SmbiosRecord->BiosVersion = VersionRef;
199+
SmbiosRecord->BiosReleaseDate = ReleaseDateRef;
200+
201+
OptionalStrings = (CHAR8 *)(SmbiosRecord + 1);
202+
// publish the string set
203+
StringTablePublishStringSet (
204+
&StrTable,
205+
OptionalStrings,
206+
(SmbiosRecordSize - sizeof (SMBIOS_TABLE_TYPE0))
207+
);
208+
// setup the header
209+
SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BIOS_INFORMATION;
210+
SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);
211+
CmObject = BiosInfo->BiosInfoToken;
212+
213+
*Table = (SMBIOS_STRUCTURE *)SmbiosRecord;
214+
*CmObjectToken = CmObject;
215+
216+
exit:
217+
// free string table
218+
StringTableFree (&StrTable);
219+
return Status;
220+
}
221+
222+
/** The interface for the SMBIOS Type0 Table Generator.
223+
*/
224+
STATIC
225+
CONST
226+
SMBIOS_TABLE_GENERATOR SmbiosType0Generator = {
227+
// Generator ID
228+
CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType00),
229+
// Generator Description
230+
L"SMBIOS.TYPE0.GENERATOR",
231+
// SMBIOS Table Type
232+
EFI_SMBIOS_TYPE_BIOS_INFORMATION,
233+
// Build table function
234+
BuildSmbiosType0Table,
235+
// Free function
236+
FreeSmbiosType0Table,
237+
NULL,
238+
NULL
239+
};
240+
241+
/** Register the Generator with the SMBIOS Table Factory.
242+
243+
@param [in] ImageHandle The handle to the image.
244+
@param [in] SystemTable Pointer to the System Table.
245+
246+
@retval EFI_SUCCESS The Generator is registered.
247+
@retval EFI_INVALID_PARAMETER A parameter is invalid.
248+
@retval EFI_ALREADY_STARTED The Generator for the Table ID
249+
is already registered.
250+
**/
251+
EFI_STATUS
252+
EFIAPI
253+
SmbiosType0LibConstructor (
254+
IN EFI_HANDLE ImageHandle,
255+
IN EFI_SYSTEM_TABLE *SystemTable
256+
)
257+
{
258+
EFI_STATUS Status;
259+
260+
Status = RegisterSmbiosTableGenerator (&SmbiosType0Generator);
261+
DEBUG ((
262+
DEBUG_INFO,
263+
"SMBIOS Type 0: Register Generator. Status = %r\n",
264+
Status
265+
));
266+
ASSERT_EFI_ERROR (Status);
267+
268+
return Status;
269+
}
270+
271+
/** Deregister the Generator from the SMBIOS Table Factory.
272+
273+
@param [in] ImageHandle The handle to the image.
274+
@param [in] SystemTable Pointer to the System Table.
275+
276+
@retval EFI_SUCCESS The Generator is deregistered.
277+
@retval EFI_INVALID_PARAMETER A parameter is invalid.
278+
@retval EFI_NOT_FOUND The Generator is not registered.
279+
**/
280+
EFI_STATUS
281+
EFIAPI
282+
SmbiosType0LibDestructor (
283+
IN EFI_HANDLE ImageHandle,
284+
IN EFI_SYSTEM_TABLE *SystemTable
285+
)
286+
{
287+
EFI_STATUS Status;
288+
289+
Status = DeregisterSmbiosTableGenerator (&SmbiosType0Generator);
290+
DEBUG ((
291+
DEBUG_INFO,
292+
"SMBIOS Type0: Deregister Generator. Status = %r\n",
293+
Status
294+
));
295+
ASSERT_EFI_ERROR (Status);
296+
return Status;
297+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## @file
2+
# SMBIOS Type0 Table Generator
3+
#
4+
# Copyright (c) 2024 - 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5+
# Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.<BR>
6+
#
7+
# SPDX-License-Identifier: BSD-2-Clause-Patent
8+
##
9+
10+
[Defines]
11+
INF_VERSION = 0x0001001B
12+
BASE_NAME = SmbiosType0LibArm
13+
FILE_GUID = 8f95040b-4846-4c7e-b5c1-e4565bfcfa4b
14+
VERSION_STRING = 1.0
15+
MODULE_TYPE = DXE_DRIVER
16+
LIBRARY_CLASS = NULL|DXE_DRIVER
17+
CONSTRUCTOR = SmbiosType0LibConstructor
18+
DESTRUCTOR = SmbiosType0LibDestructor
19+
20+
[Sources]
21+
SmbiosType0Generator.c
22+
23+
[Packages]
24+
MdePkg/MdePkg.dec
25+
MdeModulePkg/MdeModulePkg.dec
26+
EmbeddedPkg/EmbeddedPkg.dec
27+
ArmPlatformPkg/ArmPlatformPkg.dec
28+
DynamicTablesPkg/DynamicTablesPkg.dec
29+
30+
[Protocols]
31+
gEfiSmbiosProtocolGuid # PROTOCOL ALWAYS_CONSUMED
32+
33+
[LibraryClasses]
34+
BaseLib
35+
DebugLib
36+
SmbiosStringTableLib
37+
MemoryAllocationLib

0 commit comments

Comments
 (0)